multthrd.c illustrates a number of Open Server multithreaded programming features, including:
Creation of a service thread using srv_spawn
Interthread communication between client connection threads and the service thread using message queues (using srv_getmsgq and srv_putmsgq)
Sleep and wake-up mechanisms (using srv_sleep and srv_wakeup)
The use of a callback routine (using srv_callback) to report scheduling information
multthrd.c installs a SRV_START handler, a SRV_LANGUAGE handler, a SRV_CONNECT handler, and callback handlers. A service thread logs all the language queries received by the Open Server application. The following occurs:
In the application’s language handler, the client thread reads the query from a client and sends a message to the service thread, known as the logger, with the query as the message data.
The client thread then waits (srv_sleep). When the service thread receives the message, it wakes up the client thread (srv_wakeup).
The logger continuously loops waiting for messages. When it receives a message, it prints the contents of the query to a file and alerts the sender.
The logger and client threads install SRV_C_RESUME, SRV_C_SUSPEND, SRV_C_TIMESLICE, and SRV_C_EXIT callback handlers to print scheduling information.