C++ 中的執行緒 get_id() 函式。
在該教程中,我們將討論一個瞭解 C++ 中的執行緒 get_id() 函式的程式。
執行緒 get_id() 函式驗證程序當前的狀態,然後返回正在執行的當前執行緒的 ID。此函式不採用任何引數。
例項
#include <chrono>
#include <iostream>
#include <thread>
using namespace std;
//creating thread
void sleepThread(){
this_thread::sleep_for(chrono::seconds(1));
}
int main(){
thread thread1(sleepThread);
thread thread2(sleepThread);
thread::id t1_id = thread1.get_id();
thread::id t2_id = thread2.get_id();
cout << "ID associated with thread1= " << t1_id << endl;
cout << "ID associated with thread2= " << t2_id << endl;
thread1.join();
thread2.join();
return 0;
}輸出
ID associated with thread1= 135456142132844 ID associated with thread2= 135121414221716
廣告
資料結構。
網路。
關係資料庫管理系統。
作業系統。
Java。
iOS。
HTML。
CSS。
Android。
Python。
C 程式設計。
C++。
C#。
MongoDB。
MySQL。
Javascript。
PHP。