Namespaces
Variants
Views
Actions

std::unique_lock::unique_lock

From cppreference.com
< cpp‎ | thread‎ | unique lock
Revision as of 17:42, 2 November 2012 by P12bot (Talk | contribs)

 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
 
 

Template:ddcl list begin <tr class="t-dcl ">

<td >
unique_lock();
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
unique_lock( unique_lock&& other );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
explicit unique_lock( mutex_type& m );
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
unique_lock( mutex_type& m, std::defer_lock_t t );
</td>

<td > (4) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
unique_lock( mutex_type& m, std::try_to_lock_t t );
</td>

<td > (5) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
unique_lock( mutex_type& m, std::adopt_lock_t t );
</td>

<td > (6) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Rep, class Period >

unique_lock( mutex_type& m,

             const std::chrono::duration<Rep,Period>& timeout_duration );
</td>

<td > (7) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class Clock, class Period >

unique_lock( mutex_type& m,

             const std::chrono::time_point<Clock,Duration>& timeout_time );
</td>

<td > (8) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Constructs a unique_lock, optionally locking the supplied mutex.

1) Constructs a unique_lock with no associated mutex.

2) Move constructor. Initializes the unique_lock with the contents of other.

3-8) Constructs a unique_lock with m as the associated mutex. Additionally:

3) Locks the associated mutex by calling m.lock().
4) Does not lock the associated mutex.
5) Tries to lock the associated mutex without blocking by calling m.try_lock().
6) Assumes the calling thread already owns m.
7) Tries to lock the associated mutex. Blocks until specified timeout_duration has elapsed or the lock is acquired, whichever comes first. May block for longer than timeout_duration.
8) Tries to lock the associated mutex. Blocks until specified timeout_time has been reached or the lock is acquired, whichever comes first. May block for longer than until timeout_time has been reached.

Parameters

other - another unique_lock to initialize the state with
m - mutex to associate with the lock and optionally acquire ownership of
t - tag parameter used to select constructors with different locking strategies
timeout_duration - maximum duration to block for
timeout_time - maximum time point to block until

Exceptions

1, 2, 4)
noexcept specification:  
noexcept
  

Example