首页 > 其他分享 >boost sleep sleep_for 休眠函数

boost sleep sleep_for 休眠函数

时间:2023-03-28 15:06:49浏览次数:40  
标签:const 未定义 timespec 休眠 thread sleep boost

boost

boost线程中表示睡眠的函数有sleep和sleep_for

头文件:#include <boost/thread.hpp>


sleep

例如:

boost::this_thread::sleep(boost::posix_time::seconds(2));

表示睡眠两秒钟。还有millsec/millseconds、micro/microseconds表示毫秒和微秒。


sleep_for

例如:

boost::this_thread::sleep_for(boost::chrono::seconds(2));

同样表示睡眠两秒钟。还有millseconds、microseconds、nanoseconds表示毫秒,微秒,纳秒。

要注意:sleep使用posix_time,sleep_for使用chrono。


错误

对‘boost::this_thread::hidden::sleep_until(timespec const&)’未定义的引用

可能错误一:Linux编译Makefile没有添加-lpthread  -lboost_thread动态库链接

可能错误二:Linux下boost库头文件需要重新生成

qpid/rabbitmqconsumer.o:在函数‘sleep’中:

/opt/cmms/3thrdparty/boost/include/boost/thread/pthread/thread_data.hpp:278:对‘boost::this_thread::hidden::sleep_until(timespec const&)’未定义的引用

/opt/cmms/3thrdparty/boost/include/boost/thread/pthread/thread_data.hpp:278:对‘boost::this_thread::hidden::sleep_until(timespec const&)’未定义的引用

标签:const,未定义,timespec,休眠,thread,sleep,boost
From: https://blog.51cto.com/fengyuzaitu/6154895

相关文章