1 Threads线程
1.1 Functions managing the current thread管理当前线程函数
2 Mutual exclusion互斥量
2.1 Generic mutex management通用互斥管理
2.2 Generic locking algorithms通用锁算法
2.3 Call once单次调用
3 Condition variables条件变量
4 Futures未来
Threads
Threads enable the program to execute across several processor cores.
//线程使程序可以跨多个核(心)运行。
Defined in header <thread> //定义在<thread>头文件
thread
(C++11)
manages a separate thread //管理一个独立线程
(class)
Functions managing the current thread//管理当前线程的函数
Defined in namespace this_thread //定义在名字空间域this_thread
yield
(C++11)
hints the implementation to reschedule execution of threads
(function)//提示实现重新安排线程的执行,即调用yield将降低优先级。
get_id
(C++11)
returns the thread id of the current thread
(function)//返回线程标识
sleep_for
(C++11)
stops the execution of the current thread for a specified time duration
(function)//持续停止当前线程一段时间
sleep_until
(C++11)
stops the execution of the current thread until a specified time point
(function)//停止当前线程直到某个时间点
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> //定义在<mutex>头文件
mutex
(C++11)
provides basic mutual exclusion facility
(class)//提供基本互斥量
timed_mutex
(C++11)
provides mutual exclusion facility which implements locking with a timeout
(class)//提供超时互斥量(超时解锁)
recursive_mutex
(C++11)
provides mutual exclusion facility which can be locked recursively by the same thread
(class)//提供能被同一线程递归上锁的互斥量
recursive_timed_mutex
(C++11)
provides mutual exclusion facility which can be locked recursively
by the same thread and implements locking with a timeout
(class)//提供能被同一线程递归上锁且有超时的互斥量。(超市解锁)
Generic mutex management//通用互斥量管理
lock_guard
(C++11)
implements strictly scope-based mutex ownership wrapper
(class template)//基于严格作用域互斥的封装(退出作用域时自动被unlock)
unique_lock
(C++11)
implements movable mutex ownership wrapper
(class template)//可移动的互斥封装(独占锁,可设超时)
defer_lock_t
try_to_lock_t
adopt_lock_t
tag type used to specify locking strategy
(class)//定义指定锁策略的类型
defer_lock
try_to_lock
adopt_lock
tag constants used to specify locking strategy
(constant)//指定锁定策略的常量
Generic locking algorithms//通用锁算法
try_lock
(C++11)
locks specified mutexes/locks, returns false if at least one is unavailable
(function template)//锁上指定的互斥/锁,如果都不能行则返回false
lock
(C++11)
locks specified mutexes/locks, blocks if at least one is unavailable
(function template)//锁上指定的互斥/锁,只要有一个不行就阻塞。
Call once //调用一次
once_flag
(C++11)
helper object to ensure that call_once invokes the function only once
(class)//帮助对象确保其调用函数只有一次
call_once
(C++11)
invokes a function only once even if called from multiple threads
(function template)//即使多线程调用也只调用一次函数
Condition variables//条件变量
A condition variable is a synchronization primitive which implements a list of threads that are waiting until another thread notifies one or all of the waiting threads that they may proceed, until a timeout expires, or until a spurious wakeup occurs. A condition variable is always associated with a mutex.
//一个条件变量是一个同步原语,实现了一个列表的线程等待另一个线程通知一个或所有的等待线程,他们可能继续进行,直到一个超时过期,或直到一个虚假唤醒发生。一个条件变量总是关联到一个互斥锁。
condition_variable
(C++11)
provides a condition variable assocaited with std::unique_lock
(class)//提供一个和std::unique_lock关联的条件变量
condition_variable_any
(C++11)
provides a condition varibale associated with any lock type
(class)//提供一个和任意锁类型关联的条件变量
notify_all_at_thread_exit
(C++11)
schedules a call to notify_all to be invoked when this thread exits
(function)//线程退出时调用一个调度(call)通告所有
cv_status
(C++11)
lists the possible results of timed waits on condition variables
(class)//列出了定时等待条件变量的可能的结果
Futures//未来
This section is incomplete//此章节是未完成的
Defined in header <future> //在头文件<future>定义
promise
(C++11)
stores a value for asynchronous retrieval
(class template)//存储异步返回值
packaged_task
(C++11)
packages a function to store its return value for asynchronous retrieval
(class template)//为异步返回值打包一个函数来存储它的返回值
future
(C++11)
waits for a value that is set asynchronously
(class template)//等待一个异步设置的值
shared_future
(C++11)
waits for a value that is set asynchronously. The internal state is shared among several objects
(class template)//等待一个异步设置的值,内部状态是几个对象之间共享
async
(C++11)
provides a facility to launch a function in a new thread and acquire its return value asynchronously
(function template)//提供一种工具来启动一个函数在一个新线程和异步获取其返回值