Rediger

Del via


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.

Syntax

class recursive_mutex;

Members

Public Constructors

Name Description
recursive_mutex Constructs a recursive_mutex object.
~recursive_mutex Destructor Releases any resources that are used by the recursive_mutex object.

Public Methods

Name Description
lock Blocks the calling thread until the thread obtains ownership of the mutex.
try_lock Attempts to obtain ownership of the mutex without blocking.
unlock Releases ownership of the mutex.

Requirements

Header: <mutex>

Namespace: std

lock

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.

recursive_mutex

Constructs a recursive_mutex object that is not locked.

recursive_mutex();

~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.

try_lock

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.

unlock

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.

See also

Header Files Reference
<mutex>