|Implements a very fast, non reentrant mutex. More...|
|This is a reentrant mutex with spinlock. More...|
|This is an advanced (and fully reentrant) read/write mutex. More...|
|This is a read/write mutex. More...|
|Advanced mutex class. More...|
A mutex can be locked by a thread to prevent other threads to lock it; if a mutex is locked a second time, the thread that tries to lock it must wait for the previous locker to unlock it. If a given mutex is always used in conjuntion with a given set of data, then a thread can lock a mutex to be sure that, when it is able to proceed after the lock() statement, the data is untouchable until the lock is released.
Mutex can be used also to exclude mutual access to functions or processes. I.e., a program may want to write data on a log file, then a mutex can be used to prevent concurrent access to the file handle (data lock) but also to prevent any other thread from calling functions that are going to write log entries (functional lock).
In Object Oriented Programming, a class may have a mutex as member and methods that access the class data concurrently may lock it to allow only being executed only by one thread at a time.
A special kind of mutexes are the so called read-write mutexes. Those objects allow two different kind of locking: read only locking and write locking. The principle is that, if many threads are reading a set of data that is not going to change it is useless to lock it; only when a thread wants to alter that set of data is necessary to prevent other threads from mangling with data at the same moment.