Changes

Jump to: navigation, search

Computer Science/162/proj1

543 bytes added, 04:35, 5 October 2008
Implementation
===Implementation===
;New state variables
*'''PriorityQueue''' – {{c|KThread lastThreadThreadState holder, ArrayList<ThreadState> waitQueue, int effective, boolean dirty}}<br />*'''ThreadState''' – {{c|int donatedPriorityeffective, boolean dirty, HashSet<PriorityQueue> myResources, WaitingOn}}<br />*'''PriorityScheduler''' – {{c|PriorityQueue.holder - this ThreadState corresponds to the holder of the resource signified by the PriorityQueue.waitQueue - an ArrayList<KThread> of ThreadStates waiting on this resource. Unsorted.PriorityQueue.dirty - set to true when a new thread is added to the queue, or any of the queues in the waitQueue flag themselves as dirty.PriorityQueue.effective - the cached highest of the effective priorities in the waitQueue}}. This value is invalidated while dirty is true. ThreadState.myResources - collection of PriorityQueues that signify the Locks or other resources that this thread currently holds.ThreadState.waitingOn - collection of PriorityQueues corresponding to resources that this thread has attempted to acquire but could not.ThreadState.effective - the cached effective priority of this thread. this value is invalidated when dirty is trueThreadState.dirty - set to true when this thread's priority is changed, or when one of the queues in myResources flags itself as dirty. 
;Implementation details
* PriorityQueue.nextThread()* This method retrieves and removes the highest priority thread off the Priority-Time setArrayList. It calculates then flags the previous holder of this threadresource as dirty, and removes the queue from that holder's priority based on priorities of the threads waiting in resource list. It then sets the retrieved thread to this queue's new holder, and flags that thread as dirty as well.* PriorityQueue. It resets acquire(KThread thread)* Sets the priority holder of this queue to the specified thread previously in , bypassing the lastThread position to its original priorityqueue. The thread to be returned is also set Resets previous holder and sets dirty flags as the new lastThreadin nextThread(). * PriorityQueue.pickNextThread()* This method Simply retrieves the first highest priority thread from the Priority-Time set without removing it from the set. It creates a new ThreadState from off this thread and returns the ThreadStatequeue. * PriorityQueue.getEffectivePriority()* This method sums the associated thread's priority and its donatedPriority. If this sum queue is less than 7"dirty", returns the method returns maximum of each of the sumThreadStates. Otherwise, getEffectivePriority() in this queue. Those calls in turn become mutually recursive when they call getEffectivePriority on the max priority 7 is returnedPriorityQueues in their myResrouces.
* setPriority()
This method will change the actual priority of the thread associated with the ThreadState. The effective priority of lastThread must also be by difference between current threads priority and new priority.
* waitForAccess(priorityQueue) This method puts thread associated with the threadState onto the Priority-Time set. The set sorts all threads by priority, then time. The associated thread will then be put to sleep. This method will also recalculate effective priority: it will add up all priorities of the threads in the set and donate it to the lastThread.* acquire()* This method calculates the priority of the associated thread based on priorities of the threads waiting in the queue. It resets the priority of the thread previously in the lastThread position to its original priority. The associated thread is set as the new lastThread.
===Testing===
Anonymous user

Navigation menu