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 }