由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++ 怎么让一段程序每10秒钟run一次?
相关主题
求建议:C++的TCP/IP编程库xgboost 里面的tree到底是一整个depth=N的树,还是一个binary
C++多线程的选择原来你们扭扭捏捏不好意思说的比较优势就是web service啊
pthread on windows?为什么用try catch不住exception?
有人熟悉c++ Qt吗?请教一个在 AIX 下编译运行的问题
C++11痛并快乐着再次请教关于AIX中线程以及优先级的问题
boost vs C++11How to set a timer in C?
Pthread support on Windows XPWindows Thread API
help on pthreads.....请帮忙看个thread的问题 (with memory dump)
相关话题的讨论汇总
话题: boost话题: xt话题: alarm话题: 3s话题: 10
进入Programming版参与讨论
1 (共1页)
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.

1 (共1页)
进入Programming版参与讨论
相关主题
请帮忙看个thread的问题 (with memory dump)C++11痛并快乐着
About volatile in Cboost vs C++11
这是怎么回事?Pthread support on Windows XP
关于valgrind 的一个问题help on pthreads.....
求建议:C++的TCP/IP编程库xgboost 里面的tree到底是一整个depth=N的树,还是一个binary
C++多线程的选择原来你们扭扭捏捏不好意思说的比较优势就是web service啊
pthread on windows?为什么用try catch不住exception?
有人熟悉c++ Qt吗?请教一个在 AIX 下编译运行的问题
相关话题的讨论汇总
话题: boost话题: xt话题: alarm话题: 3s话题: 10