#include <pmutex.h>
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. | |
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().
Definition at line 40 of file pmutex.h.
|
|
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.
|
|
|
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. |
|
|
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.
Referenced by P::Mutex::Lock::operator=(). |
|
|
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.
|
|
|
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.
|
1.3.3