Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MCMutex Class Reference

Base class for all mutual exclusion primitives. More...

#include <mcllib/MCMutex.h>

Inheritance diagram for MCMutex:

MCCondVar MCInMutex MCMonitor MCRWMutex MCSemaphore MCTestMutex MCFileMutex List of all members.

Public Member Functions

virtual void lock ()=0
 Lock the mutex object.
virtual void unlock ()=0
 Unlock the mutex object.
virtual ~MCMutex ()
 Allow virtual destruction.

Detailed Description

Base class for all mutual exclusion primitives.

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.


Member Function Documentation

virtual void lock  )  [pure virtual]
 

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.

virtual void unlock  )  [pure virtual]
 

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.


Generated on Wed Jan 12 19:05:49 2005 for MCLLIB by  doxygen 1.3.9.1