Thread-safe code and preemptive mode

More than one Open Server thread can be running at the same time, and one can be preempted in favor of another. This has the benefit of increased concurrency, especially in SMP systems. However, it does require code to be thread-safe. This applies to Open Server code, the user's event handlers and callback functions.


SRV_S_PREEMPT behavior

When SRV_S_PREEMPT is set to CS_TRUE, multiple Open Server threads execute concurrently and are preempted in favor of each other by the operating system. These threads become unbound.

If SRV_S_PREEMPT is set to CS_FALSE, one Open Server thread cannot be preempted by another Open Server thread, and two Open Server threads cannot run at the same time.

Also, whether SRV_S_PREEMPT is set to CS_TRUE or CS_FALSE, when used in conjunction with threaded libraries, some functions of SRV_S_CURTHREAD become disabled. This is because threaded libraries use signals handled by a signal-handled thread, regardless of the SRV_S_PREEMPT setting.

A single mutex is enabled whenever an Open Server thread resumes executing. The mutex is released when an Open Server thread is ready with a specific task and after the SRV_C_SUSPEND callback is executed. There is only one server-wide mutex for this.The callback functions SRV_C_RESUME and SRV_C_SUSPEND are never invoked when the operating system resumes such a thread. These functions are invoked only when a specific Open Server thread stops or resumes execution; for instance, when a language request arrives for a user Open Server thread, and before it goes to sleep after running the language event handler.