Edit

Share via


<mutex> functions and variables

adopt_lock

Represents an object that can be passed to constructors for lock_guard and unique_lock to indicate that the mutex object that is also being passed to the constructor is locked.

const adopt_lock_t adopt_lock;

call_once

Provides a mechanism for calling a specified callable object exactly once during execution.

template <class Callable, class... Args>
void call_once(once_flag& Flag,
    Callable F&&, Args&&... A);

Parameters

Flag
A once_flag object that ensures that the callable object is only called once.

F
A callable object.

A
An argument list.

Remarks

If Flag is not valid, the function throws a system_error that has an error code of invalid_argument. Otherwise, the template function uses its Flag argument to ensure that it calls F(A...) successfully exactly once, regardless of how many times the template function is called. If F(A...) exits by throwing an exception, the call was not successful.

defer_lock

Represents an object that can be passed to the constructor for unique_lock. This indicates that the constructor should not lock the mutex object that's also being passed to it.

const defer_lock_t defer_lock;

lock

Attempts to lock all arguments without deadlock.

template <class L1, class L2, class... L3>
void lock(L1&, L2&, L3&...);

Remarks

The arguments to the template function must be mutex types, except that calls to try_lock might throw exceptions.

The function locks all of its arguments without deadlock by calls to lock, try_lock, and unlock. If a call to lock or try_lock throws an exception, the function calls unlock on any of the mutex objects that were successfully locked before rethrowing the exception.

swap

template <class Mutex>
void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;

try_lock

template <class L1, class L2, class... L3> int try_lock(L1&, L2&, L3&...);

try_to_lock

Represents an object that can be passed to the constructor for unique_lock to indicate that the constructor should try to unlock the mutex that is also being passed to it without blocking.

const try_to_lock_t try_to_lock;