I am working on a multithreaded WinForms component in some spare cycles.
There are a heap of worker threads and to keep the UI responsive I set the priority of the worker threads to below normal. Its a technique that works really well.
The component raises events that the UI responds to. In testing the event handlers I checked the thread priority to make sure that it had bubbled up from the component in below normal priority. I discovered that it was in normal priority. Something was very strange.
It turns out in .Net when you start a thread it starts in normal priority, not the priority of the thread that launched it. To get around this you need a some class member that records what the thread priority should be and when a new thread starts it needs to check this member and set its own priority accordingly.
I can't help but think that this was a poor design decision.
Apparently Java's thread do inherit their priority from their parent.
No comments:
Post a Comment