Jump to content
  • Advertisement
Sign in to follow this  
Floating

Sleep and Windows XP

This topic is 4797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have an application with several threads running. When I call Sleep(1) in a given thread, the thread will sleep between 10-15 miliseconds instead of 1. I heard this is specific to Windows XP. How can I get my thread to sleep only 1 (or x) miliseconds. Is there maybe a possibility to set the resolution of thread-swapping lower? (change some operating system variable?) Thanks a lot

Share this post


Link to post
Share on other sites
Advertisement
The resolution of the Sleep function will vary from an absolute minimal possible of 10ms to anything above based on hardware and bios. There is nothing you can do about it to the best of my knowledge. Quick read here.

Share this post


Link to post
Share on other sites
You can't. There is no guarantee on the upper bound on the amount of time until your thread is woken. If you need that, you'll have to investigate a real-time OS. You could play with the priority level of your thread a bit and it might help (don't starve the system!), but, in the end, there is still no definite bound.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i've found that the Sleep time resolution is governed by the multimedia timer. but i've never been able to go below 10ms.


TIMECAPS tc;
timeGetDevCaps(&tc, sizeof(tc));
...
timeBeginPeriod(tc.wPeriodMin);
Sleep(m_snooze);
timeEndPeriod (tc.wPeriodMin);
DoWorkHere...
...


Share this post


Link to post
Share on other sites
You can use the timeBeginPeriod(1) to request the fastest swapping the OS will allow. There's no good reason why a modern PC can't swap at 1000Hz deterministically, but it seems that the faster systems actually have higher limits. We used to get ~1.0ms swaps on 300MHz systems, but a 2.4Ghz swaps at 1.6ms.

The guarantee provided by the Win32 Sleep function is that the thread will sleep for at least as long as you request (which is actually more certainty than you get from posix).

Share this post


Link to post
Share on other sites
Quote:
Original post by Shannon Barber


I'll have to definitly give that a try sometime - I've never seen that informaton before anywhere. Doing Google searches on timeBeginPeriod now gets a lot of great infomration on this issue, thanks for sharing! I guess there is something you can do about it. If only MSDN had better cross-referencing...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!