During initial e-Link web service development, I played around with lowering the priority of a background processing thread. It didn’t need to run in real time and having the service handling client requests was more important. For a background housekeeping thread, I lowered it’s priority to BelowNormal.
Well that didn’t work quite the way I expected it. That thread never ran, or it ran so seldom that it was effectively useless. So I removed the calls to lowering the thread priority and life was good again. I chalked it up to one of those thread things not to touch and moved on to other tasks.
Today, I saw a posting on the Coding Horror that explained why you should never mess with thread prioirities. If you have a thread running at a lower priority and it enters a sleep state, it may never wake up if another thread with a higher priority continues to run. That’s an oversimplification, the actual details are described better here by Joe Duffy.
The moral of today’s story is “Set up your threads at normal priority and let the operating system deal with scheduling them“