Public Member Functions | Private Attributes

Threads::Mutex::ScopedLock Class Reference

List of all members.

Public Member Functions

 ScopedLock (Mutex &m)
 ~ScopedLock ()

Private Attributes

Mutexmutex

Detailed Description

Scoped lock class. When you declare an object of this type, you have to pass it a mutex, which is locked in the constructor of this class and unlocked in the destructor. The lock is thus held during the entire lifetime of this object, i.e. until the end of the present scope, which explains where the name comes from. This pattern of using locks with mutexes follows the resource-acquisition-is-initialization pattern, and was used first for mutexes by Doug Schmidt. It has the advantage that locking a mutex this way is thread-safe, i.e. when an exception is thrown between the locking and unlocking point, the destructor makes sure that the mutex is unlocked; this would not automatically be the case when you lock and unlock the mutex "by hand", i.e. using acquire and release.

Definition at line 342 of file thread_management.h.


Constructor & Destructor Documentation

Threads::Mutex::ScopedLock::ScopedLock ( Mutex m) [inline]

Constructor. Lock the mutex.

Definition at line 349 of file thread_management.h.

References Threads::Mutex::acquire(), and mutex.

Threads::Mutex::ScopedLock::~ScopedLock ( ) [inline]

Destructor. Unlock the mutex. Since this is a dummy mutex class, this of course does nothing.

Definition at line 357 of file thread_management.h.

References mutex, and Threads::Mutex::release().


Member Data Documentation

Store the address of the mutex object.

Definition at line 364 of file thread_management.h.

Referenced by ScopedLock(), and ~ScopedLock().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Mon May 21 2012 12:06:37 by doxygen 1.7.3