Linux下的睡眠函數sleep(),thread創建線程,求Linux系統的時間間隔


1、.cc文件下的睡眠函數:

this_thread::sleep_for(chrono::seconds(1));睡眠1秒

2、eg:  g++ multithread.cc -o multithread -std=c++11 -lpthread

-std=C++11 :表示采用C++11標准

-lpthread :表示   線程庫。

3、用thread創建線程

 

 4、join()的作用:阻塞主線程。

5、線程函數帶參數

 

 6、使用Linux計算兩時間戳間的時間:

1 struct timeval start_time,end_time;
2 gettimeofday(&start_time,NULL);
3 double time_used=end_time.tv_sec-start_time.tv_sec+(end_time.tv_usec-start_time.tv_usec)/1000000.0;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM