Main Page Class Hierarchy Compound List File List Compound Members File Members
guard< Lock > Class Template Reference
List of all members.
Detailed Description
template<class Lock = mutex>
class guard< Lock >
A class which acquires a lock on creating and destroys it on destruction.
It is typically used like so:
mutex my_mutex;
int my_function()
{
guard g(my_mutex);
do_some_exclusive_stuff();
if (some_condition())
return 1;
do_other_stuff();
return 0;
}
The mutex is automatically released whenever the guard goes out of scope, so you don't need to worry about releasing the mutex in case of exception (e.g., in do_some_exclusive_stuff) or if a code block ends early (e.g., returns 1 in that if clause).
The above function is actually better written using the locking(x) macro.
Constructor & Destructor Documentation
template<class Lock = mutex> |
guard< Lock >::guard |
( |
const guard< Lock > & |
g |
) |
|
|
template<class Lock = mutex> |
guard< Lock >::guard |
( |
Lock & |
m |
) |
|
|
template<class Lock = mutex> |
guard< Lock >::guard |
( |
Lock * |
m |
) |
|
|
template<class Lock = mutex> |
guard< Lock >::~guard |
( |
|
) |
|
|
Member Function Documentation
template<class Lock = mutex> |
guard< Lock >::operator bool |
( |
|
) |
const |
|
template<class Lock = mutex> |
guard& guard< Lock >::operator= |
( |
const guard< Lock > & |
g |
) |
|
|
The documentation for this class was generated from the following file:
Generated on Fri Dec 20 13:35:10 2002 for NMSTL