我有运行循环的线程.我需要该循环每 5 毫秒运行一次(1 毫秒错误).我知道 Sleep() 函数不精确.
您有什么建议吗?
更新.我不能以其他方式做到这一点.在循环结束时,我需要某种睡眠.我也不想 100% 加载 CPU.
从问题标签来看,我猜你是在 Windows 上.看看多媒体计时器,他们宣传精度低于 1 毫秒.另一种选择是使用 Spin Locks 但这基本上会使 CPU 核心保持最大使用率.>
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.
Do you have any suggestions?
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.
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 误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 C++ 中读取和操作 CSV 文件数据?How can I read and manipulate CSV file data in C++?(如何在 C++ 中读取和操作 CSV 文件数据?)
在 C++ 中,为什么我不能像这样编写 for() 循环:In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,为什么我不能像这样编写 for() 循环: for(
OpenMP 如何处理嵌套循环?How does OpenMP handle nested loops?(OpenMP 如何处理嵌套循环?)
在循环 C++ 中重用线程Reusing thread in loop c++(在循环 C++ 中重用线程)
是否需要“do {...} while ()"?环形?Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?环形?)
如何从交换机内部跳出循环?How to break out of a loop from inside a switch?(如何从交换机内部跳出循环?)