The scheduling method determines when control is transferred from one running thread to another. An Open Server application uses one of two scheduling methods: non-preemptive or preemptive. Non-preemptive is the default method and the only method available on most platforms.
With non-preemptive scheduling, context switches are predictable. They can occur only in these situations:
A thread calls a Server-Library or Client-Library routine that performs network I/O.
When a thread reads from or writes to a network connection, the runtime system suspends execution of the thread waiting for the read or write to complete. Network I/O is relatively slow, and the server can use the time more efficiently by allowing other threads to run while the I/O completes.
A thread sleeps while waiting for execution to resume.
For example, a thread should wait for another thread to finish updating a data object in shared memory before accessing the object. A thread sleeps when the application calls:
srv_sleep
One of the Server-Library routines where the thread sleeps while waiting for a requested resource, such as srv_getmsgq(SRV_M_WAIT) or srv_lockmutex
A thread calls srv_yield to intentionally suspend itself and allow other threads to run. The thread remains executable and resumes operation later at the statement after the srv_yield call. If you write a time-consuming routine that does not sleep or perform network I/O, you should call srv_yield occasionally to prevent the routine from monopolizing the server.
With preemptive scheduling, a context switch can occur when any of the above events occurs, or when the system interrupts the running thread. Preemptive scheduling depends upon the thread management facilities of the operating system, so system-initiated context switches are not predictable. Operating systems often employ sophisticated algorithms to ensure optimal time distribution among threads.
You can choose preemptive scheduling using the srv_props routine with property set to SRV_S_PREEMPT. Preemptive scheduling is not available on every platform. Call srv_capability to determine whether it is available on your application’s platform.