LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1211|回复: 4

有比SDL_AddTimer()精度更高的定时器可以用吗?

[复制链接]
发表于 2006-12-29 16:13:01 | 显示全部楼层 |阅读模式
SDL_AddTimer()的定时器只能精确到10毫秒级别,有没有精确到1毫秒的定时器可以替代啊.
请高手指点!
发表于 2006-12-29 17:27:58 | 显示全部楼层
nanosleep ?
可以到纳秒级别,但实际的精度我不清楚,不过据我一个写流媒体服务器的同学说,还不错。

不过这个并不像 timer 那样属于回调性质,只能自己手工计算每次的延时
回复 支持 反对

使用道具 举报

发表于 2006-12-31 12:23:47 | 显示全部楼层
BUGS
       The current implementation of nanosleep() is based on the normal kernel
       timer  mechanism,  which  has  a  resolution  of  1/HZ s (see time(7)).
       Therefore, nanosleep() pauses always for at least the  specified  time,
       however it can take up to 10 ms longer than specified until the process
       becomes runnable again. For the same reason, the value returned in case
       of  a  delivered  signal  in *rem is usually rounded to the next larger
       multiple of 1/HZ s.

实际上的nanosleep并不可用,除非你是实时内核。因为,实际上,你的程序从sleep到再运行,几乎都要10ms,如此算来,计时精度极限也就是10ms了,这个在当前的内核里没有办法改进了。
回复 支持 反对

使用道具 举报

发表于 2006-12-31 12:48:59 | 显示全部楼层
请楼上翻译一下:
which has a resolution of 1/HZ s

the value returned in case of a delivered signal in *rem is usually rounded to the next larger multiple of 1/HZ s.
回复 支持 反对

使用道具 举报

发表于 2006-12-31 18:34:04 | 显示全部楼层
Post by xiaoshao_0_0
BUGS
       The current implementation of nanosleep() is based on the normal kernel
       timer  mechanism,  which  has  a  resolution  of  1/HZ s (see time(7)).
       Therefore, nanosleep() pauses always for at least the  specified  time,
       however it can take up to 10 ms longer than specified until the process
       becomes runnable again. For the same reason, the value returned in case
       of  a  delivered  signal  in *rem is usually rounded to the next larger
       multiple of 1/HZ s.

实际上的nanosleep并不可用,除非你是实时内核。因为,实际上,你的程序从sleep到再运行,几乎都要10ms,如此算来,计时精度极限也就是10ms了,这个在当前的内核里没有办法改进了。

这一点我也是知道的,所以我才说并不确定它的实际精度为多少。但是据同学的经验来看,即使是在多媒体这样要求实时性的应用场合中它也可以较好的满足需求。我想如果有必要,还是楼主自己实际测试一下比较好(不是说它测它的精度,而是说自己是否真的需要那么高的计时精度)
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表