December 20th, 2007

Consequences of the scheduling algorithm: Low priority threads can take 100% CPU

I see variations on this question occasionally. “Why is my low priority thread consuming 100% CPU?” Setting a thread to low priority doesn’t mean that it won’t consume lots of CPU. It just means that it doesn’t get to run as long as there is a higher-priority thread ready to run. But if there is a CPU looking for something to do, and there is no higher-priority thread that is runnable, your low-priority thread will run, and if your low-priority thread is CPU-intensive, it will get all the CPU.

Priority merely controls which threads get first dibs on CPU time, but if you arrange so that your thread is the only one who wants to run, then it get all the CPU. The chicken at the bottom of the pecking order gets to eat all it wants if no higher-rank chickens are around. You paid for that CPU. There’s no point withholding it just out of spite.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.