Does SetThreadPriority cause thread reschedulling?

Posted by Suma on Stack Overflow See other posts from Stack Overflow or by Suma
Published on 2010-04-14T13:49:54Z Indexed on 2010/04/14 13:53 UTC
Read the original article Hit count: 151

Consider following situation, assuming single CPU system:

  • thread A is running with a priority THREAD_PRIORITY_NORMAL, signals event E
  • thread B with a priority THREAD_PRIORITY_LOWEST is waiting for an event E (Note: at this point the thread is not scheduled because it is runnable, but A is higher priority and runnable as well)
  • thread A calls SetThreadPriority(B, THREAD_PRIORITY_ABOVE_NORMAL)

Is thread B re-scheduled immediately to run, or is thread A allowed to continue until current time-slice is over, and B is scheduled only once a new time-slice has begun?

I would be interested to know the answer for WinXP, Vista and Win7, if possible.

Note: the scenario above is simplified from my real world code, where multiple threads are running on multiple cores, but the main object of the question stays: does SetThreadPriority cause thread scheduling to happen?

© Stack Overflow or respective owner

Related posts about winapi

Related posts about threads