#include <mcllib/MCMutex.h>
Inheritance diagram for MCMutex:
Public Member Functions | |
virtual void | lock ()=0 |
Lock the mutex object. | |
virtual void | unlock ()=0 |
Unlock the mutex object. | |
virtual | ~MCMutex () |
Allow virtual destruction. |
The derived classes have the same semantics for lock, but may be compound structures where only part is locked. The intention is that derived classes are used in aggregation where locking of derived class is required
Mutex objects are used to ensure multiple threads do not concurrently access data or perform a task. Only one thread at once can have called lock() and returned from it. It is the responsibility of the calling thread to call unlock() after it has called lock(). This is best achieved by using the MCLock class which performs automatic scope-based locking and unlocking of a MCMutex derived object. Example usage
void foo() { MCLock lck(&mtx); // lock the mutex. other threads block ... access the data protected by mutex... // mutex is automatically unlocked when MCLock is destructed }The example assume that mtx is an MCMutex derived object.
|
Lock the mutex object. If another thread has locked the mutex object and has not yet unlocked it, the calling thread blocks indefinitely until the other thread calls unlock(). Implemented in MCCondVar, MCFileMutex, MCInMutex, MCMonitor, MCRWMutex, and MCSemaphore. |
|
Unlock the mutex object. If there are any threads blocked waiting for the mutex to be unlocked, one of them will be woken up. Implemented in MCCondVar, MCFileMutex, MCInMutex, MCMonitor, MCRWMutex, and MCSemaphore. |