Namespaces
Variants
Views
Actions

std::lock_guard

From cppreference.com
< cpp‎ | thread
Revision as of 17:42, 19 April 2012 by P12bot (Talk | contribs)

Template:cpp/thread/lock guard/sidebar

Defined in header <mutex>
template< class Mutex >
class lock_guard;
(since C++11)

The class Template:cpp implements a strictly scope-based mutex ownership wrapper. The class is non-copyable. The supplied Mutex type shall implement the Lockable concept.

Member types

Template:tdcl list begin Template:tdcl list hitem Template:tdcl list item Template:tdcl list end

Member functions

Template:cpp/thread/lock guard/dcl list constructorTemplate:cpp/thread/lock guard/dcl list destructorTemplate:tdcl list end

Example

std::mutex m;
 
void do_something()
{
    std::lock_guard<std::mutex> lock(m);
    // the remaining function is thread-safe now
}