問題描述
我有運行循環的線程.我需要該循環每 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模板網!