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创建线程

Linux下的睡眠函数sleep(),thread创建线程,求Linux系统的时间间隔

 

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

5、线程函数带参数

Linux下的睡眠函数sleep(),thread创建线程,求Linux系统的时间间隔

 

 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;

 

原文链接: https://www.cnblogs.com/technicist/p/12655752.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    Linux下的睡眠函数sleep(),thread创建线程,求Linux系统的时间间隔

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/340536

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月2日 上午12:39
下一篇 2023年3月2日 上午12:39

相关推荐