Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To much processor Utilization

Status
Not open for further replies.

fonnerk

Programmer
Joined
May 9, 2002
Messages
2
Location
US
I have a while loop in my MS C++ Code that is constantly checking if another process is finished. The problem is that while this while loop is running it pratically uses all the cpu just running this while loop. Why is that. I have noticed this in some other spots as well. Other apps are slowing down when it does this too. Is there a way I can control this? Any help is appreciated!

Thanks,
Kevin
 
While your app is in a while loop, it does not return to its messageloop (which is where GetMessage() makes the thread "sleep" until something happens). This is the reason that your thread is consuming 100% CPU.

I have no idea of how you're checking for the other process to have been completed, but if it is with WaitForSingleObject, the problem would be solved by specifying some value for the dwMilliseconds argument other than 0. If you're testing another way using the Sleep() API will slow your thread down.

For your other While loops I suggest using Sleep(0) if their hanging up other processes. This results in your thread to "give" its remaining time slice to any other thread of equal priority.
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top