Click to See Complete Forum and Search --> : Forcing a thread ...
RogerGarrett
February 8th, 2006, 01:09 PM
I've got a situation where I have a number of threads running at the same time. One of them is performing a very labor-intensive process and seems to be "hogging" the CPU. Is there a way to tell a thread to "yield" so that other threads can have a chance at some CPU time?
- Roger Garrett
googler
February 8th, 2006, 01:19 PM
Use SwitchToThread() API
Arjay
February 8th, 2006, 01:53 PM
Use SwitchToThread() APIWith all respect, it's usually better to let the OS handle the thread switching. You may need to check what actually is going on in the thread that is hogging the cpu. Is it polling? Is it set to the wrong priority? You can get a thread to yield its time-slice by simply adding a Sleep(0) statement.
Arjay
googler
February 8th, 2006, 02:00 PM
With all respect, it's usually better to let the OS handle the thread switching.
HUH????? SwitchToThread() is an OS API for switching threads.
Arjay
February 8th, 2006, 02:58 PM
HUH????? SwitchToThread() is an OS API for switching threads.You are correct. Having never needed to use this function, I incorrectly assumed it allowed you to specify the thread.
kirants
February 8th, 2006, 05:45 PM
Arjay brings up a good point.. Usually, this is the sign of some form of polling which quite often can be replaced by some waitable call that suspends the thread till an event occurs ( e.g. WaitFor family of functions, or using GetMessage instead of PeekMessage or using overlapped I/O instead of polling ). So, details on what the thread is doing would be good
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.