std::lock_guard::lock_guard

From cppreference.com
< cpp‎ | thread‎ | lock guard
 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
(C++11)
Generic lock management
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
 
std::lock_guard
Member functions
lock_guard::lock_guard
 
explicit lock_guard( mutex_type& m );
(1) (since C++11)
lock_guard( mutex_type& m, std::adopt_lock_t t );
(2) (since C++11)
lock_guard( const lock_guard& ) = delete;
(3) (since C++11)

Acquires ownership of the given mutex m.

1) If m is not a recursive mutex, requires that the current thread does not own m. Effectively calls m.lock().

2) Requires that the current thread owns m.

3) Copy constructor is deleted.

The behavior is undefined if m is destroyed before the lock_guard object is.

[edit] Parameters

m - mutex to acquire ownership of
t - tag parameter used to select non-locking version of the constructor

[edit] Exceptions

Throws any exceptions thrown by m.lock()