Reference documentation for deal.II version Git e03361e799 2019-09-18 18:08:31 -0600
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
Public Types | Public Member Functions | List of all members
Threads::Mutex Class Reference

#include <deal.II/base/thread_management.h>

Inherits mutex.

Public Types

using ScopedLock = std::lock_guard< std::mutex >
 

Public Member Functions

 Mutex ()=default
 
 Mutex (const Mutex &)
 
Mutexoperator= (const Mutex &)
 
void acquire ()
 
void release ()
 

Detailed Description

A class implementing a mutex. Mutexes are used to lock data structures to ensure that only a single thread of execution can access them at the same time.

Differences to std::mutex and copy semantics

This class is like std::mutex in almost every regard and in fact is derived from std::mutex. The only difference is that this class is copyable when std::mutex is not. Indeed, when copied, the receiving object does not copy any state from the object being copied, i.e. an entirely new mutex is created. These semantics are consistent with the common use case if a mutex is used as a member variable to lock the other member variables of a class: in that case, the mutex of the copied-to object should only guard the members of the copied-to object, not the members of both the copied-to and copied-from object. Since at the time when the class is copied, the destination's member variable is not used yet, its corresponding mutex should also remain in its original state.

Author
Wolfgang Bangerth, 2002, 2003, 2009

Definition at line 88 of file thread_management.h.

Member Typedef Documentation

◆ ScopedLock

using Threads::Mutex::ScopedLock = std::lock_guard<std::mutex>

This declaration introduces a scoped lock class. It is deprecated: use std::lock_guard<std::mutex> or any of the other, related classes offered by C++ instead.

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 Mutex::acquire() and Mutex::release().

Definition at line 111 of file thread_management.h.

Constructor & Destructor Documentation

◆ Mutex() [1/2]

Threads::Mutex::Mutex ( )
default

Default constructor.

◆ Mutex() [2/2]

Threads::Mutex::Mutex ( const Mutex )
inline

Copy constructor. As discussed in this class's documentation, no state is copied from the object given as argument.

Definition at line 122 of file thread_management.h.

Member Function Documentation

◆ operator=()

Mutex& Threads::Mutex::operator= ( const Mutex )
inline

Copy operators. As discussed in this class's documentation, no state is copied from the object given as argument.

Definition at line 132 of file thread_management.h.

◆ acquire()

void Threads::Mutex::acquire ( )
inline

Acquire a mutex.

Deprecated:
This function is deprecated. Use the std::mutex::lock() function of the base class instead.

Definition at line 146 of file thread_management.h.

◆ release()

void Threads::Mutex::release ( )
inline

Release the mutex again.

Deprecated:
This function is deprecated. Use the std::mutex::unlock() function of the base class instead.

Definition at line 159 of file thread_management.h.


The documentation for this class was generated from the following file: