다음을 통해 공유


timed_mutex Class

 

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

Represents a timed mutex type. Objects of this type are used to enforce mutual exclusion through time-limited blocking within a program.

Syntax

class timed_mutex;

Members

Public Constructors

Name Description
timed_mutex::timed_mutex Constructor Constructs a timed_mutex object that's not locked.
timed_mutex::~timed_mutex Destructor Releases any resources that are used by the timed_mutex object.

Public Methods

Name Description
timed_mutex::lock Method Blocks the calling thread until the thread obtains ownership of the mutex.
timed_mutex::try_lock Method Attempts to obtain ownership of the mutex without blocking.
timed_mutex::try_lock_for Method Attempts to obtain ownership of the mutex for a specified time interval.
timed_mutex::try_lock_until Method Attempts to obtain ownership of the mutex until a specified time.
timed_mutex::unlock Method Releases ownership of the mutex.

Requirements

Header: mutex

Namespace: std

timed_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 behavior is undefined.

timed_mutex::timed_mutex Constructor

Constructs a timed_mutex object that is not locked.

timed_mutex();

timed_mutex::~timed_mutex Destructor

Releases any resources that are used by the mutex object.

~timed_mutex();

Remarks

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

timed_mutex::try_lock Method

Attempts to obtain ownership of the mutex without blocking.

bool try_lock();

Return Value

true if the method successfully obtains ownership of the mutex; otherwise, false.

Remarks

If the calling thread already owns the mutex, the behavior is undefined.

timed_mutex::try_lock_for Method

Attempts to obtain ownership of the mutex without blocking.

template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& Rel_time);

Parameters

Rel_time
A chrono::duration object that specifies the maximum amount of time that the method attempts to obtain ownership of the mutex.

Return Value

true if the method successfully obtains ownership of the mutex; otherwise, false.

Remarks

If the calling thread already owns the mutex, the behavior is undefined.

timed_mutex::try_lock_until Method

Attempts to obtain ownership of the mutex without blocking.

template <class Clock, class Duration>
bool try_lock_for(const chrono::time_point<Clock, Duration>& Abs_time);

bool try_lock_until(const xtime* Abs_time);

Parameters

Abs_time
A point in time that specifies the threshold after which the method no longer attempts to obtain ownership of the mutex.

Return Value

true if the method successfully obtains ownership of the mutex; otherwise, false.

Remarks

If the calling thread already owns the mutex, the behavior is undefined.

timed_mutex::unlock Method

Releases ownership of the mutex.

void unlock();

Remarks

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

See Also

Header Files Reference
<mutex>