recursive_mutex Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at recursive_mutex Class.

Represents a mutex type. In contrast to mutex, the behavior of calls to locking methods for objects that are already locked is well-defined.

class recursive_mutex;

Public Constructors

NameDescription
recursive_mutex::recursive_mutex ConstructorConstructs a recursive_mutex object.
recursive_mutex::~recursive_mutex DestructorReleases any resources that are used by the recursive_mutex object.

Public Methods

NameDescription
recursive_mutex::lock MethodBlocks the calling thread until the thread obtains ownership of the mutex.
recursive_mutex::try_lock MethodAttempts to obtain ownership of the mutex without blocking.
recursive_mutex::unlock MethodReleases ownership of the mutex.

Header: mutex

Namespace: std

Blocks the calling thread until the thread obtains ownership of the mutex.

void lock();

Remarks

If the calling thread already owns the mutex, the method returns immediately, and the previous lock remains in effect.

Constructs a recursive_mutex object that is not locked.

recursive_mutex();

Releases any resources that are used by the object.

~recursive_mutex();

Remarks

If the object is locked when the destructor runs, the behavior is undefined.

Attempts to obtain ownership of the mutex without blocking.

bool try_lock() noexcept;

Return Value

true if the method successfully obtains ownership of the mutex or if the calling thread already owns the mutex; otherwise, false.

Remarks

If the calling thread already owns the mutex, the function immediately returns true, and the previous lock remains in effect.

Releases ownership of the mutex.

void unlock();

Remarks

This method releases ownership of the mutex only after it is called as many times as lock and try_lock have been called successfully on the recursive_mutex object.

If the calling thread does not own the mutex, the behavior is undefined.

Header Files Reference
<mutex>

Show: