1. 程式人生 > >28.lambda表達式與多線程

28.lambda表達式與多線程

main void get_id window box lee get seconds nds

 1 #include <iostream>
 2 #include <thread>
 3 #include <Windows.h>
 4 #include <chrono>
 5 using namespace std;
 6 
 7 
 8 void main()
 9 {
10     //獲取線程id
11     thread th1([]() {
12         //等待
13         this_thread::sleep_for(chrono::seconds(2));
14         //讓CPU先執行其他線程,空閑的時候再執行
15 this_thread::yield(); 16 cout << this_thread::get_id(); 17 //到某個時刻到來之前一直等待 18 //this_thread::sleep_until(); 19 }); 20 thread th2([]() {MessageBoxA(0, "1", "2", 0); }); 21 22 23 24 cin.get(); 25 }

28.lambda表達式與多線程