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