Skip to content

Latest commit

 

History

History
80 lines (51 loc) · 1.89 KB

lock-guard-class.md

File metadata and controls

80 lines (51 loc) · 1.89 KB
description title ms.date f1_keywords ms.assetid
Learn more about: lock_guard Class
lock_guard Class
11/04/2016
mutex/std::lock_guard
mutex/std::lock_guard::lock_guard
57121f0d-9c50-481c-b971-54e64df864e0

lock_guard Class

Represents a template that can be instantiated to create an object whose destructor unlocks a mutex.

Syntax

template <class Mutex>
class lock_guard;

Remarks

The template argument Mutex must name a mutex type.

Members

Public Typedefs

Name Description
lock_guard::mutex_type Synonym for the template argument Mutex.

Public Constructors

Name Description
lock_guard Constructs a lock_guard object.
lock_guard::~lock_guard Destructor Unlocks the mutex that was passed to the constructor.

Requirements

Header: <mutex>

Namespace: std

lock_guard::lock_guard Constructor

Constructs a lock_guard object.

explicit lock_guard(mutex_type& Mtx);

lock_guard(mutex_type& Mtx, adopt_lock_t);

Parameters

Mtx
A mutex type object.

Remarks

The first constructor constructs an object of type lock_guard and locks Mtx. If Mtx is not a recursive mutex, it must be unlocked when this constructor is called.

The second constructor does not lock Mtx. Mtx must be locked when this constructor is called. The constructor throws no exceptions.

lock_guard::~lock_guard Destructor

Unlocks the mutex that was passed to the constructor.

~lock_guard() noexcept;

Remarks

If the mutex does not exist when the destructor runs, the behavior is undefined.

See also

Header Files Reference
<mutex>