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

P::Mutex Class Reference
[Core library]

Mutex synchronization object. More...

#include <pmutex.h>

List of all members.

Public Member Functions

 Mutex (const char *name=0) throw (SyncError)
 Default constructor.

 ~Mutex () throw ()
 Destructor.

void lock () throw (SyncError)
 Lock the mutex.

bool tryLock (unsigned int timeout) throw (SyncError)
 Try locking the mutex with timeout.

void unlock () throw (SyncError)
 Unlock the mutex.


Detailed Description

Mutex synchronization object.

A Mutex is a mutual exclusion device. It is used to synchronize the access to data which is accessed by more than one thread or process at the same time. Mutexes are recursive, that is the same thread can lock a mutex multiple times without deadlocking. When unlocking the mutex, unlock() must be called for each time a thread has successfully called lock() or tryLock().

See also:
RWLock
Author:
Christian Prochnow <cproch@seculogix.de>

Definition at line 40 of file pmutex.h.


Constructor & Destructor Documentation

P::Mutex::Mutex const char *  name = 0  )  throw (SyncError)
 

Default constructor.

Construct the Mutex object. If a name is given, the mutex can be shared by multiple processes, otherwise a process-local mutex is created. On POSIX systems named mutexes are implemented using a shared memory segment which contains the pthread_mutex_t structure.

Parameters:
name a pointer to the name of the mutex which is used to identify the mutex, or a NULL pointer if the mutex should be process-local. On POSIX systems the name must reffer to an existing file and the process must be able to stat() the file.
Exceptions:
SyncError 

P::Mutex::~Mutex  )  throw ()
 

Destructor.

The destructor destroys the mutex. The mutex must be in unlocked state when the destructor is called. On POSIX systems this also removes the shared memory segment which contains the pthread_mutex_t structure if no more processes references to it.


Member Function Documentation

void P::Mutex::lock  )  throw (SyncError)
 

Lock the mutex.

Locks the mutex. If the mutex is currently locked by another thread, the calling thread suspends until no other thread holds a lock on it. If the mutex is already locked by the calling thread the function returns immediatly with incrementing the lock- count of the mutex. This prevents a thread from dead-locking while waiting for a mutex it already owns. To release its ownership under such circumstances the thread must unlock the mutex once for each time the thread has locked the mutex.

See also:
Mutex::Lock
Exceptions:
SyncError 

Referenced by P::Mutex::Lock::operator=().

bool P::Mutex::tryLock unsigned int  timeout  )  throw (SyncError)
 

Try locking the mutex with timeout.

This method does the same than lock() but also supports a timeout- value. If the lock cannot be acquired in the given interval the method returns without locking the mutex and a FALSE return value.

Parameters:
timeout the timeout in milliseconds to wait for the mutex. If zero is specified the method returns immediatly.
Returns:
TRUE if the mutex has been locked, FALSE otherwise.
Exceptions:
SyncError 

void P::Mutex::unlock  )  throw (SyncError)
 

Unlock the mutex.

Unlocks the mutex. If the mutex was locked more than one time by the same thread unlock decrements the lock-count. The mutex is actually unlocked when the lock-count is zero.

Exceptions:
SyncError 


The documentation for this class was generated from the following file:
Generated on Fri Mar 12 21:08:35 2004 for P::Classes by doxygen 1.3.3