🔒 Locked
Threading question
Advertisement
Original Post
I am making a program which will be the only program running on a machine (besides the OS). The program itself does not need to be multi-threaded, however, should I have the program use Sleep in a continuous loop? My reason for this is, if I do not do this, more than likely it will use 100% clock cycles for no reason, no?
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.
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.
If your program is the only one running besides the OS, why do you care if you hog CPU time?
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?
Quote:
Original post by Driv3MeFar
If your program is the only one running besides the OS, why do you care if you hog CPU time?
Power consumption, heat, fan noise...
Quote:Because it uses a lot more power, the fan has to go faster, and the battery time of a laptop under these conditions it dramatically shortened.
Original post by Driv3MeFar
If your program is the only one running besides the OS, why do you care if you hog CPU time?
You should use a sleep(1). Don't worry about anyone telling you that it might sleep for 15ms on the odd occasion. Windows is not a RTOS anyway, and you shouldn't need it to be any more accurate.
Sleep is generally a bad idea. It is better to wait for vblank (D3DPRESENT_INTERVAL_DEFAULT or D3DPRESENT_INTERVAL_ONE). That way your program doesn't waste time (and power) drawing frames that can't be seen anyway.
Quote:Unless you need to do other idle processing that is non-blocking, yes.
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?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement