Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread"

From cppreference.com
< cpp
(move dcl list items to templates)
(formatting)
Line 18: Line 18:
 
===Mutual exclusion===
 
===Mutual exclusion===
  
Several classes are provided that manage mutexes: {{rlt|mutex}}, {{rlt|recursive_mutex}}, {{rlt|timed_mutex}}, {{rlt|recursive_timed_mutex}}.
+
Mutual exclusion algorithms restrict access to a shared resource so that only one thread can access it at a time. This allows to avoid data races and to implement synchronization between threads.
 
+
Several class templates are provided for generic mutex management: {{rlt|lock_guard}}, {{rlt|unique_lock}}.
+
 
+
[[once_flag]] {{todo}}
+
 
+
Several helper functions are provided for mutex locking:
+
  
 
{{dcl list begin}}
 
{{dcl list begin}}
 
{{dcl list header | mutex}}
 
{{dcl list header | mutex}}
{{dcl list fun | s={{{s|}}} | try_lock | tries to lock specified mutexes or locks, returns if at least one is unavailable}}
+
{{dcl list class | cpp/thread/mutex | provides basic mutual exclusion facility | notes={{mark c++0x}}}}
{{dcl list fun | s={{{s|}}} | lock | locks specified mutexes/locks, blocks if at least one is unavailable}}
+
{{dcl list class | cpp/thread/recursive_mutex | provides mutual exclusion facility which can be locked recursively by the same thread | notes={{mark c++0x}}}}
{{dcl list fun | s={{{s|}}} | call_once | {{todo}} }}
+
{{dcl list class | cpp/thread/timed_mutex | provides mutual exclusion facility which implements locking with a timeout | notes={{mark c++0x}}}}
 +
{{dcl list class | cpp/thread/recursive_timed_mutex | provides mutual exclusion facility which can be locked recursively<br> by the same thread and implements locking with a timeout | notes={{mark c++0x}}}}
 +
{{dcl list h2 | Generic mutex management}}
 +
{{dcl list tclass | cpp/thread/lock_guard | implements strictly scope-based mutex ownership wrapper | notes={{mark c++0x}}}}
 +
{{dcl list tclass | cpp/thread/unique_lock | implements movable mutex ownership wrapper | notes={{mark c++0x}}}}
 +
{{dcl list h2 | Generic locking algorithms}}
 +
{{dcl list fun | cpp/thread/try_lock | locks specified mutexes/locks, returns {{cpp|false}} if at least one is unavailable | notes={{mark c++0x}}}}
 +
{{dcl list fun | cpp/thread/lock | locks specified mutexes/locks, blocks if at least one is unavailable | notes={{mark c++0x}}}}
 
{{dcl list end}}
 
{{dcl list end}}
+
 
 +
{{todo | reason=call_once, once_flag}}
 +
 
 
===Condition variables===
 
===Condition variables===
  
 
{{todo}}
 
{{todo}}
  
==Futures==
+
===Futures===
  
 
{{todo}}
 
{{todo}}

Revision as of 12:34, 16 July 2011

Template:cpp/thread/sidebar

Contents

Threads

Threads enable the program to execute across several processor cores.

Template:cpp/thread/dcl list threadTemplate:cpp/thread/dcl list yieldTemplate:cpp/thread/dcl list get idTemplate:cpp/thread/dcl list sleep forTemplate:cpp/thread/dcl list sleep until
Defined in header <thread>
Functions managing current thread
Defined in namespace this_thread

Mutual exclusion

Mutual exclusion algorithms restrict access to a shared resource so that only one thread can access it at a time. This allows to avoid data races and to implement synchronization between threads.

Defined in header <mutex>
provides basic mutual exclusion facility
(class)
provides mutual exclusion facility which can be locked recursively by the same thread
(class)
provides mutual exclusion facility which implements locking with a timeout
(class)
provides mutual exclusion facility which can be locked recursively
by the same thread and implements locking with a timeout
(class)
Generic mutex management
implements strictly scope-based mutex ownership wrapper
(class template)
implements movable mutex ownership wrapper
(class template)
Generic locking algorithms
locks specified mutexes/locks, returns Template:cpp if at least one is unavailable
(function)
locks specified mutexes/locks, blocks if at least one is unavailable
(function)

Condition variables

Futures