Mutexes

A mutual exclusion semaphore, or mutex, is a logical object that Open Server allows one thread, at most, to lock. It is useful for protecting shared resources and for building more sophisticated tools.

To understand how a mutex can be used, consider this problem:

The standard input and output is the same for every thread in an Open Server application running on a UNIX platform. If threads regularly write to the standard output, the application code must avoid mixing the output of several threads on the standard output.

One way to prevent threads from mixing their output is to associate a mutex with the stdout device and require a thread to lock the mutex before writing to stdout. Since only one thread can lock the mutex at a time, only one thread can write on stdout at a time. Other threads have to wait until they are able to lock the mutex.

See the srv_createmutex, srv_lockmutex, srv_unlockmutex and srv_deletemutex reference pages for programming details.