#include <Guard.h>

Public Member Functions | |
Guard (LockType &lock) | |
Guard (LockType &lock, unsigned long timeout) | |
template<class U , class V > | |
Guard (Guard< U, V > &g) | |
Guard (Guard &g) | |
template<class U , class V > | |
Guard (Guard< U, V > &g, LockType &lock) | |
Guard (Guard &g, LockType &lock) | |
~Guard () throw () | |
Friends | |
class | LockHolder< LockType > |
Detailed Description
class ZThread::Guard< LockType, LockingPolicy >
- Date
- <2003-07-16T17:55:42-0400>
- Version
- 2.2.0
Scoped locking utility. This template class can be given a Lockable synchronization object and can 'Guard' or serialize access to that method.
For instance, consider a case in which a class or program have a
Mutex object associated with it. Access can be serialized with a Guard as shown below.
The Guard will lock the synchronization object when it is created and automatically unlock it when it goes out of scope. This eliminates common mistakes like forgetting to unlock your mutex.
An alternative to the above example would be
HOWEVER; using a Guard in this method is dangerous. Depending on your compiler an anonymous variable like this can go out of scope immediately which can result in unexpected behavior. - This is the case with MSVC and was the reason for introducing assertions into the Win32_MutexImpl to track this problem down
Constructor & Destructor Documentation
◆ Guard() [1/6]
|
inline |
Create a Guard that enforces a the effective protection scope throughout the lifetime of the Guard object or until the protection scope is modified by another Guard.
- Parameters
-
lock LockType the lock this Guard will use to enforce its protection scope.
- Postcondition
- the protection scope may be ended prematurely
◆ Guard() [2/6]
|
inline |
Create a Guard that enforces a the effective protection scope throughout the lifetime of the Guard object or until the protection scope is modified by another Guard.
- Parameters
-
lock LockType the lock this Guard will use to enforce its protection scope.
- Postcondition
- the protection scope may be ended prematurely
◆ Guard() [3/6]
◆ Guard() [4/6]
◆ Guard() [5/6]
◆ Guard() [6/6]
◆ ~Guard()
The documentation for this class was generated from the following file:
- Guard.h