<mutex> functions

Visual Studio 2015
 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at <mutex> functions and variables.

adopt_lock Variable](#adopt_lock_variable)|call_once Function|defer_lock Variable|
|lock Function|try_to_lock Variable|

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;

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.

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;

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.

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;

<mutex>

Show: