Jive reference manual
|
Locks and unlocks mutual exclusion objects. More...
#include <jem/base/Lock.h>
Public Member Functions | |
Lock (const M &mutex) | |
Locks a mutual exclusion object. More... | |
~Lock () | |
Unlocks the mutual exclusion object. More... | |
The class Lock
can be instantiated for all types M that declare the member functions lock()
and unlock()
. Here is an example:
Because the destructor of the Lock
class automatically unlocks the mutual exclusion object, it allows one to lock such an object in an exception safe way.
Monitor
, Mutex
, ReadWriteMutex
, RecursiveMonitor
, RecursiveMutex
. The constructor of the Lock
class locks a mutual exclusion object by calling its lock()
member function. The constructor casts away the constness of the mutual exclusion variable so that the lock()
member does not have to be declared const. The reason for declaring the parameter mutex as const is that a lock/unlock pair does not logically change the state of the mutex.
mutex | - the mutual exclusion object to be locked. The lifetime this object must exceed the lifetime of this Lock object. |