thread sleep

发布时间 2023-06-27 20:21:51作者: yhbb123

(27条消息) C++11 多线程thread的休眠sleep_for chrono_chrono sleep_tomorrow00hello的博客-CSDN博客

 

 1 using namespace std;
 2 void ppp()
 3 {
 4     for (int i=0;i<50;i++)
 5     {
 6         cout << "hello " << endl;
 7     }
 8     
 9 }
10 void ppp1()
11 {
12     for (int i = 0; i < 50; i++)
13     {
14         cout << "hello1 " << endl;
15     }
16 
17 }
18 
19 int main()
20 {
21     
22 
23     //thread(ppp).join();
24     //thread(ppp1).join();
25 
26     thread a(ppp);
27     thread b(ppp1);
28     a.join();
29     b.join();
30 31 cout << "hello1 " << endl; 32 33 34 35 36 return 0; 37 }

两种不一样

thread a(ppp);
thread b(ppp1);
a.join();
b.join();  join占用一个核心做事情

 

//thread(ppp).join();
//thread(ppp1).join();