std::lock_guard::lock_guard - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::lock_guard::lock_guard

From cppreference.com
< cpp‎ | thread‎ | 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) Effectively calls m.lock(). The behavior is undefined if `m` is not a recursive mutex and the current thread already owns `m`.
2) Acquires ownership of the mutex m without attempting to lock it. The behavior is undefined if the current thread does not own `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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/thread/lock_guard/lock_guard&oldid=90544"