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)//提供一種工具來啟動一個函數在一個新線程和異步獲取其返回值