k**l 发帖数: 2966 | 1 I know there is a sleep(10), 不过这个是等待10秒,如果我的程序本身要比如2~3s
才能完成就得等7~8s,应该有个类似sleep的library 能设定每10s开始运行一次吧,
boost里面有么?谢谢 |
m*****e 发帖数: 4193 | 2 alarm
but be careful with signal handlers - they are limited in functionality.
A better way is to use select() or pthread, depending on your case.
3s
,
【在 k**l 的大作中提到】 : I know there is a sleep(10), 不过这个是等待10秒,如果我的程序本身要比如2~3s : 才能完成就得等7~8s,应该有个类似sleep的library 能设定每10s开始运行一次吧, : boost里面有么?谢谢
|
r*********r 发帖数: 3195 | 3 boost::asio. pretty neat stuff.
btw, using select() is not portable. |
k**l 发帖数: 2966 | 4 looks like pretty hardcore, reading the documents...
btw, about the simplest solution "alarm()", if my code took 2.35s to finish,
it can only wait 8s(or 7s?) instead of the desired 7.65s, right?
【在 r*********r 的大作中提到】 : boost::asio. pretty neat stuff. : btw, using select() is not portable.
|
r*********r 发帖数: 3195 | 5 alarm() 's timer is not very accurate. get/setitimer() can be precise up to
microsec. |
p**p 发帖数: 3386 | 6 正如楼上有人说的,pthread可以做到,而且精度高
3s
,
【在 k**l 的大作中提到】 : I know there is a sleep(10), 不过这个是等待10秒,如果我的程序本身要比如2~3s : 才能完成就得等7~8s,应该有个类似sleep的library 能设定每10s开始运行一次吧, : boost里面有么?谢谢
|
k**l 发帖数: 2966 | 7 懂boost的人能帮忙看看这段程行么:只要myEngineOn==true; myEngine_run() 每10秒
钟被call一次:
while(myEngineOn){
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec+=10;
myEngine_run(); //这个function应该不会超过两秒
boost::thread::sleep(xt);
//这里的意思是睡到xt, 不是睡xt那么长时间---If I understand
}
【在 r*********r 的大作中提到】 : boost::asio. pretty neat stuff. : btw, using select() is not portable.
|