Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread/lock guard"

From cppreference.com
< cpp‎ | thread
m (Text replace - "{{cpp|" to "{{c|")
m (Text replace - "{{tdcl list begin" to "{{dcl list begin")
Line 12: Line 12:
  
 
===Member types===
 
===Member types===
{{tdcl list begin}}
+
{{dcl list begin}}
 
{{tdcl list hitem | Member type | Definition}}
 
{{tdcl list hitem | Member type | Definition}}
 
{{tdcl list item | {{tt|mutex_type}} | Mutex}}
 
{{tdcl list item | {{tt|mutex_type}} | Mutex}}

Revision as of 01:22, 12 June 2012

Template:cpp/thread/lock guard/sidebar

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

The class lock_guard 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 hitemTemplate:tdcl list itemTemplate: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
}