The 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 through 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
A service thread logs all the language queries received by this Open Server application.
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. Then, the client thread waits (srv_sleep). When the service thread gets the message, it wakes up the client thread (srv_wakeup). The logger thus continuously loops, waiting for messages. When it receives a message, it prints the contents of the query to a file and wakes up 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. The multthrd.c program installs a SRV_START handler, a SRV_LANGUAGE handler, a SRV_CONNECT handler, and callback handlers.