Free Web Hosting | free host | Free Web Space | BlueHost Review

WST 18 - Thread Priorities
Home Up Interests Downloads (New) My Resume Links Feedback

 

Interests
Downloads (New)
My Resume
Links
WST
Feedback

Hi all,

Today we will see Thread Priorities. As you all must be aware, the OS uses thread scheduling to schedule different threads for their time slices. Now in doing this, the OS has to make sure that threads doing important work, are not starved for CPU time (time slice) while others, less important threads are scheduled. These kinds of situations are resolved with the help of Thread Priorities. Thread priorities are simple points above or below normal priority, which are assigned to a thread. Depending this point, the thread scheduler decides to pre-empt or keep running a thread when a new thread is ready for scheduling.

Apart from the priority of a thread (Also called the priority level of the thread) there is a priority class for each PROCESS. The priority class for the process decides the priorities to be assigned to the threads created in that process. So the scheduler combines the process priority class and the thread priority level to form a BASE PRIORITY for the thread.

There is also a concept of priority boost on latest OS's. The priority boost is added to the base priority of a thread to improve it's responsiveness. For example, when an application is brought to the foreground, the OS increases the priority boost of it's main thread, so that the application appears more responsive to the user. The priority boosts are dynamically changed by the OS itself.

You can get or set the thread priority levels using GetThreadPriority() and SetThreadPriority() functions. You can get/set the process priority class using GetPriorityClass() and SetPriorityClass() functions.

On Multi processor systems (SMP) you can request the OS to assign your thread/process to get executed on a particular CPU. This can be achieved by SetProcessAffinityMask() and SetThreadAffinityMask() functions.

Exercises:

1. Find out all the priority levels (base) and priority classes from MSDN and study them.

2. Write an application which has a counter and displays the count. Now experiment on this application with different priority levels/classes and observe the results. You should be able to see the change in the way your application behaves.

3. Find out what security and access rights are required before you can change the priorities of your process/thread.

This should be sufficient for this week, we will try to cover some other topic next week.

Thanks for your time.

-Farooque

 

 

HyperCounter
Bpath Counter