Message queues

Message queues enable threads to communicate with each other. Message queues are often used to send data to spawned service threads that perform services for other threads. For example, you could create a message queue into which all threads put data destined for the log file. A spawned thread could read the messages from the queue and write them, in the order received, to the log file.

The message in a message queue is a 4-byte value, usually a pointer that addresses data somewhere in memory shared by the sending and receiving thread. The thread that puts a message into a queue and the threads that read the message must agree on the message format.

If the message references data elsewhere, you must make sure that the thread that reads the message finishes with the data before the thread that sent the message updates or releases the data area. To prevent the sending routine from overwriting or freeing the message before the message is received, the routine that writes messages, srv_putmsgq, has an option that causes the sending thread to sleep until the message is read from the queue.

See the srv_createmsgq, srv_putmsgq, srv_getmsgq, and srv_deletemsgq reference pages for programming details.