Delen via


unique_lock Class

Represents a template that can be instantiated to create objects that manage the locking and unlocking of a mutex.

template<class Mutex>
class unique_lock;

Remarks

The template argument Mutex must name a mutex type.

Internally, a unique_lock stores a pointer to an associated mutex object and a bool that indicates whether the current thread owns the mutex.

Members

Public Typedefs

Name

Description

unique_lock::mutex_type

Synonym for the template argument Mutex.

Public Constructors

Name

Description

unique_lock::unique_lock Constructor

Constructs a unique_lock object.

unique_lock::~unique_lock Destructor

Releases any resources that are associated with the unique_lock object.

Public Methods

Name

Description

unique_lock::lock Method

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

unique_lock::mutex Method

Retrieves the stored pointer to the associated mutex.

unique_lock::owns_lock Method

Specifies whether the calling thread owns the associated mutex.

unique_lock::release Method

Disassociates the unique_lock object from the associated mutex object.

unique_lock::swap Method

Swaps the associated mutex and ownership status with that of a specified object.

unique_lock::try_lock Method

Attempts to obtain ownership of the associated mutex without blocking.

unique_lock::try_lock_for Method

Attempts to obtain ownership of the associated mutex without blocking.

unique_lock::try_lock_until Method

Attempts to obtain ownership of the associated mutex without blocking.

unique_lock::unlock Method

Releases ownership of the associated mutex.

Public Operators

Name

Description

unique_lock::operator bool Operator

Specifies whether the calling thread has ownership of the associated mutex.

unique_lock::operator= Operator

Copies the stored mutex pointer and associated ownership status from a specified object.

Inheritance Hierarchy

unique_lock

Requirements

Header: mutex

Namespace: std

See Also

Reference

<mutex>

Other Resources

C++ Standard Library Header Files