C++并發(C++11)-01 最簡單的多線程
#include <iostream> #include <thread> using namespace std; void hello() { cout << "hello" << endl; } int main() { thread t(hello); t.join(); return 0; }
以上代碼中就包含兩個線程:“主線程”、“t線程”。主線程入口函數為“main”而t線程入口函數為“hello”。t.join()保證了主線程會等待t線程及其相關線程。

浙公網安備 33010602011771號