Selecting a thread to resume

Open Server maintains a set of run queues—lists of threads that are suspended but not sleeping. Each queue contains threads with the same execution priority. The scheduler restores the thread that has remained the longest on the highest priority queue. Threads normally run at the same priority level, so this selection method usually distributes execution time on a first-in, first-out basis.

You can adjust the priority of a thread so that the scheduler runs it before other threads in the run queue, or only when there are no other threads to run. For example, a thread that reads real-time data could have a higher priority so that it runs whenever there is data to process. Be careful when adjusting priorities. As long as a thread has a higher priority than any other and is able to run, the scheduler continues to run it. If the priority stays high and the thread never sleeps, threads with lower priorities will never run. See srv_setpri for information on adjusting a thread’s priority.

When Open Server establishes a new thread, the scheduler must perform some work before the thread can fully share CPU time with other threads. During this start-up period, the scheduler effectively performs a series of internal srv_yield calls to allow existing threads to run. As a result, established, executable threads may appear to “hog” CPU and delay start-up of the new thread. Once the thread is established and executable, it shares CPU time according to its priority.

Execution priority is only an issue in Open Server applications that run in non-preemptive mode.