Changes

Jump to: navigation, search

Computer Science/162/proj1

1,189 bytes added, 05:20, 5 October 2008
Implementation
==Priority Scheduler==
===Implementation===
 
The idea here is that Threads keep track of the PriorityQueues corresponding to both the resources that they are currently holding and those that they want to hold. We can do this via hooking PriorityQueue's waitForAccess, acquire, and nextThread.
 
Once we have this, every time a thread tries to wait on a queue, or takes control of a queue, we can tell that queue that its overall effective priority may have changed, and it can in, turn tell the thread that currently holds the resource that one of the PriorityQueues it holds may have had its priority changed. That holder can in turn tell the same to the PriorityQueues that it is waiting on, and so on. Eventually a thread holding a resource that everyone needs, but with a low priority will be marked for priority recalculation.
 
At this point recalculation is simple. The effective priority of a thread is the maximum of its own actual priority and the priorities of all the PriorityQueues that it currently holds. The effective priority of a PriorityQueue is the maximum effective priority of all the threads waiting on it (if the queue is supposed to donate priority), and so on and so forth in this mutually recursive manner.
 
;New state variables
*'''PriorityQueue''' – {{c|ThreadState holder, ArrayList<ThreadState> waitQueue, int effective, boolean dirty}}<br />
Anonymous user

Navigation menu