需要精确的线程睡眠。最大1ms错误 [英] Precise thread sleep needed. Max 1ms error

查看:98
本文介绍了需要精确的线程睡眠。最大1ms错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有线程运行循环。
我需要该循环每5ms运行一次(1ms错误)。
我知道Sleep()函数不精确。

I have thread that runs loop. I need that loop to be run once every 5ms (1ms error). I know that Sleep() function is not precise.

你有什么建议吗?

更新。
我不能以其他方式做。
在循环结束时,我需要某种睡眠。
我不想有100%的CPU加载。

Update. I can't do it other way. At the end of loop I need some kind of Sleep. I don't want to have 100% CPU loaded either.

推荐答案

在窗口。
查看多媒体计时器,它们在1ms以下发布精度。
另一种选择是使用旋转锁,但这将基本上保持cpu内核最大使用。

From the question tags I suppose you are on windows. Take a look at Multimedia Timers, they advertise precision under 1ms. Another options is to use Spin Locks but this will basically keep a cpu core at maximum usage.

这篇关于需要精确的线程睡眠。最大1ms错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆