次の方法で共有


recursive_mutex Class

 

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.

Syntax

class recursive_mutex;

Members

Public Constructors

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

Public Methods

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

Requirements

Header: mutex

Namespace: std

recursive_mutex::lock Method

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::recursive_mutex Constructor

Constructs a recursive_mutex object that is not locked.

recursive_mutex();

recursive_mutex::~recursive_mutex Destructor

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.

recursive_mutex::try_lock Method

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.

recursive_mutex::unlock Method

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>