C std this thread知識整理

2021-10-10 05:26:00 字數 1488 閱讀 1107

總結

c++11新標準引入了四個支援多執行緒的檔案,、、、、。

標頭檔案主要宣告了 std::thread 類,另外 std::this_thread 命名空間也在該標頭檔案中。

命名空間std::this_thread提供了一組關於當前執行緒的函式

使用this::this_thread::get_id()獲取執行緒id:

函式原型:std::thread::id get_id() noexcept;

cout << this_thread::get_id() << endl;

thread t( );

t.detach();

system("pause");

使用std::this_thread::yield()放棄當前執行緒占用時間片使cpu重新排程以便其它執行緒執行:

函式原型:void yield() noexcept;

bool g_ready;

void waitready() cout << "ok" << endl; }

thread t(waitready);

t.detach();

函式原型:template< class rep, class period >

void sleep_for( const std::chrono::duration& sleep_duration );

this_thread::sleep_for(chrono::nanoseconds(1000));//阻塞當前執行緒1000納秒

this_thread::sleep_for(chrono::microseconds(1000));//阻塞當前執行緒1000微妙

this_thread::sleep_for(chrono::milliseconds(1000));//阻塞當前執行緒1000毫秒

this_thread::sleep_for(chrono::seconds(20)+ chrono::minutes(1));//阻塞當前執行緒1分鐘20秒

this_thread::sleep_for(chrono::hours(1));//阻塞當前執行緒1小時

使用std::this_thread::sleeo_until()阻塞當前執行緒直到某個時間點:

函式原型:template< class clock, class duration >

void sleep_until( const std::chrono::time_point& sleep_time );

chrono::system_clock::time_point until = chrono::system_clock::now();

until += chrono::seconds(5);

this_thread::sleep_until(until);//阻塞到5秒之後

Android tensorflow 基礎知識學習

今天記錄下tensorflow的一些基本知識 1.匯入tensorflow 庫,且指令碼中新增執行使用的python環境 user bin env python import tensorflow as tf 匯入tensorflow庫 匯入 mnist 資料集 資料在linux 根目錄 data下...

Hyperledger Fabric 基礎知識筆記

區塊鏈可以幫助在競爭者之間或具有相反商業利益的組織之間建立信任,這可能導致爭執。資產在hyperledger fabric中表示為鍵值對的集合,狀態更改記錄為通道 分類賬中的事務。資產可以二進位制和 或json形式表示。chaincode是定義一項或多項資產的軟體,以及用於修改資產的交易指令 換句話...

Hyperledger Fabric基礎知識摘記

fabric是hyperledger專案的乙個子專案,它實現了區塊鏈技術,是一種基於交易呼叫和數字事件的分布式共享賬本技術。它採用模組化的架構設計,支援可插拔的元件開發和使用。fabric引入了成員管理的服務,即每個參與者都需要得到對應的證書證明身份才能夠訪問fabric系統,同時引入了多通道的概念...