Hi all, I've a question. suppose there are a number of threads in a program. each having different priority. now if i run this program on a m/c that uses time slicing as the scheduling algo. then will the priority of threads matter? In my opinion the answer is -- no I feel that all the threads will get equal CPU time irrespective of their priority and even a lower priority thread may be started by th OS even by preemping the higher priority thread if the turn of lower priority thread comes. please comment
Hi deekasha, With time-sliced thread scheduling, there is no definitive way to allocate CPU time to a specific thread, but the priorities used are one of the deciding factors in the scheduler's decision to choose a specific one. As an example, create an application that has three threads all running on different priorities. Have them print out different things in a loop perhaps . You'll see that the thread with the highest priority will finish it's job first almost every time (assuming they start at similar times) and the thread with the lowest priority will finish last almost every time.
You are right that time-sliced will not accurately utilize the priority of each thread like we as programmers may want, but it does allocate more time to the higher priority threads in the long run. I guess it just increases the odds that the higher priority threads will get CPU time. I hope that helps somewhat. Paul
Can OS allot more time to a Higher priority Thread in Time-Slice Scheduling OS ? ------------------ _SvR_ [This message has been edited by Sameer Rao (edited October 19, 2000).]
Joined: May 06, 2000
Hi Sameer, Earlier I was confused about thread scheduling but while going through JLS my doubt got clear.
JLS clearly states (last para of 17.12): Every Thread has a priority. When there is competition for processing resourcees, threads with higher priority are generally executed inprference to threads with lower priority. Such preference is not however , a guarntee that the highest priority will always be running.
Note the generally word in above quote . as far as your question goes then the straight forward answer is scheduler is free to schedule threads in accordance to the scheduling algo it follows.It may respect the priority it may not. so once u say thread.start() the control is out of your hands and scheduler may run them in any order.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com