std::lock_guard<Mutex>::lock_guard
From cppreference.com
< cpp | thread | lock guard
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Concurrency support library
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
(C++26)
(C++20)
(C++26)
(C++20)
(C++26)
(C++26)
(C++26)
(C++26)
(C++26)
(C++26)
(C++11)
(C++11)
(C++17)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++20)(C++20)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++26)
(C++26)
(C++26)
(C++11)
(C++20)
(C++11)
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
(C++11)
(C++11)
(C++11)(deprecated in C++26)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)
(C++26)(C++26)
(C++26)(C++26)
(C++11)
(C++20)(C++20)
(C++20)
(C++20)
(C++11)(C++11)
(C++11)(C++11)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
(C++20)
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) Effectively calls m.lock().
2) Acquires ownership of the mutex m without attempting to lock it. The behavior is undefined if the current thread does not hold a non-shared lock (i.e., a lock acquired by
lock
, try_lock
, try_lock_for
, or try_lock_until
) on 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
1) Throws any exceptions thrown by m.lock().
2) Throws nothing.