標頭 <thread> 提供下列函式:
get_id
可唯一識別執行目前的執行緒。
thread::id get_id() noexcept;
傳回值
一個類型唯一識別當前執行緒的物件 thread::id 。
Example
#include <iostream>
#include <thread>
int main()
{
std::thread::id current_thread_id = std::this_thread::get_id();
std::cout << "Current thread id: " << current_thread_id;
}
Current thread id: 16196
sleep_for
封鎖呼叫執行緒。
template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& Rel_time);
參數
Rel_time
一個 duration 指定時間區間的物件。
備註
函式會阻擋呼叫執行緒至少在由 Rel_time所指定的時間內。 這個函式不會擲回任何例外狀況。
sleep_until
封鎖呼叫執行緒,至少直到指定的時間。
template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& Abs_time);
參數
Abs_time
表示時間點。
備註
這個函式不會擲回任何例外狀況。
swap
交換兩個 thread 物件的狀態。
void swap(thread& Left, thread& Right) noexcept;
參數
Left
左 thread 物件。
Right
右 thread 物件。
備註
此函式會呼叫 Left.swap(Right)。
yield
向作業系統表示執行其他執行緒,即使目前的執行緒通常會繼續執行。
inline void yield() noexcept;