Changes

Jump to: navigation, search

Computer Science/162/proj1

359 bytes added, 22:17, 4 October 2008
Pseudocode
The latter two tests were run with up to 500 threads of speakers and listeners each (with a temporary override on the number of max threads in Nachos) and the number of listen and speak operations was analyzed via script. The speakers and listeners would print statements while executing code, which allowed us to perform this analysis.
===Pseudocode=== speak(int word) { Acquire the lock; While there are speakers, or while (There is an exchange is in progress:active speaker) { WS++; Sleep as a waiting speaker; WS--; Increment the number of speakers and sleep;} After waking, decrement the number of speakersAS++; Set the word to speak; Increment number of speakers if (There is an active listener) { Wake the active listener; If there are no listeners and there's no exchange in progress: Release the lock;Go to sleep Return; If there } else { if (There are waiting listeners and there's no exchange in progress:) { Wake a waiting listener; else: } Sleep as an active speaker; AS--; AL--; if (There are waiting speakers) { Wake a waiting speaker; Properly set if there is an exchange in progress or not; } Release the lock and return; Return; } } listen() { Acquire the lock;While there are other listeners or while (There is an exchange active listener) { WL++; Sleep as a waiting listener; WL--; } AL++; if (There is in progress:an active speaker) {Increment Wake an active speaker; Store the number of listeners and sleepword;After waking, decrement Release the number of speakerslock;Increment Return the number of listenersword;If there } else { if (There are no waiting speakers and there's no exhange in progress:Go to sleep;If there's no exchange in progress:) { Wake a waiting speaker;Flip the boolean that indicates if there's } Sleep as an exchange in progressactive listener;Set the return value to the speaker's word AL--; AS--; if (There are waiting listeners) { Wake a waiting listener;Decrement } Store the number of listenersword; Release the lock and return ; Return the word; } }
==Priority Scheduler==
Anonymous user

Navigation menu