Threading question

Started by
10 comments, last by Evil Steve 17 years, 9 months ago
Yeah, on windoze I have hit this sort of problem with Sleep() before. I always use WaitForSingleObject(GetCurrentThread(),MIN_YIELD_TIME); instead of Sleep() now, much better response and you can control the minimum yield time with better granularity.

The problem has also shown up with low but non-zero Sleep() times because you cannot predict what the scheduler will do even if your app is the only USER process running.
Advertisement
Quote:Original post by MCeltic33
Quote:Original post by Evil Steve
Your program will use 100% of the CPU unless it yields to the OS through Sleep() or some blocking call like WaitForSingleObject or GetMessage().

Is your application a windows based one or a console based one? If it's a windows based one, you could use GetMessage() instead of PeekMessage() in your window processing loop to still remain responsive and use 0% of the CPU when you're not doing anything.


It is a windows based application - would you recomend using GetMessage() in every form of the application?
Unless you need to do other idle processing that is non-blocking, yes.

This topic is closed to new replies.

Advertisement