有没有跨平台的sleep函数?

abblly 2006-05-10 09:47:00
或者能实现类似sleep功能的函数,跨平台的。
...全文
437 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
晨星 2006-05-11
  • 打赏
  • 举报
回复
哦,sorry,偶把概念搞错了。:(
roger_77 2006-05-10
  • 打赏
  • 举报
回复
http://www.boost.org/doc/html/thread.html

static void sleep(const xtime& xt);
Effects: The current thread of execution blocks until xt is reached.
roger_77 2006-05-10
  • 打赏
  • 举报
回复
有,boost中的thread类库中实现了这一个函数。
boost库本身就是跨平台的。


//=========自定义sleep函数===============================
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/thread/tss.hpp>

/**
*使线程暂停的函数,参数secs为休眠的秒数
*/
void Sleep(int secs)
{
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC); //得到当前时间点xt.
xt.sec += secs; //在当前时间点上加上secs秒,得到一个新的时间点,
//然后使线程休眠到指定的时间点xt.
boost::thread::sleep(xt); // sleep for secs second;
}
晨星 2006-05-10
  • 打赏
  • 举报
回复
没有,因为C++标准库中没有这么个函数。
liu_jun_ivan 2006-05-10
  • 打赏
  • 举报
回复
没有。
铖邑 2006-05-10
  • 打赏
  • 举报
回复
你可以这样

#ifdef __WIN32__
#define sleep(x) Sleep((x)*1000)
#endif
abblly 2006-05-10
  • 打赏
  • 举报
回复
谢谢!

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧