(Mutual Exclusion and Synchronization (Chapter 5
اسلاید 1: Concurrency: Mutual Exclusion and SynchronizationChapter 5
اسلاید 2: Mutual Exclusion: Hardware SupportInterrupt DisablingA process runs until it invokes an operating-system service or until it is interruptedDisabling interrupts guarantees mutual exclusionProcessor is limited in its ability to interleave programsMultiprocessingdisabling interrupts on one processor will not guarantee mutual exclusion
اسلاید 3: Mutual Exclusion: Hardware SupportSpecial Machine InstructionsPerformed in a single instruction cycleNot subject to interference from other instructionsReading and writingReading and testing
اسلاید 4: Mutual Exclusion: Hardware SupportTest and Set Instructionboolean testset (int i) {if (i == 0) {i = 1;return true;}else {return false;}}
اسلاید 5: Mutual Exclusion: Hardware SupportExchange Instructionvoid exchange(int register, int memory) {int temp;temp = memory;memory = register;register = temp;}
اسلاید 6: Mutual Exclusion Machine InstructionsAdvantagesApplicable to any number of processes on either a single processor or multiple processors sharing main memoryIt is simple and therefore easy to verifyIt can be used to support multiple critical sections
اسلاید 7: Mutual Exclusion Machine InstructionsDisadvantagesBusy-waiting consumes processor timeStarvation is possible when a process leaves a critical section and more than one process is waiting. DeadlockIf a low priority process has the critical region and a higher priority process needs, the higher priority process will obtain the processor to wait for the critical region
اسلاید 8: Producer with Circular Bufferproducer:while (true) {/* produce item v */while ((in + 1) % n == out) /* do nothing */;b[in] = v;in = (in + 1) % n}
اسلاید 9: Consumer with Circular Bufferconsumer:while (true) {while (in == out)/* do nothing */;w = b[out];out = (out + 1) % n;/* consume item w */}
اسلاید 10:
اسلاید 11: Infinite Buffer
اسلاید 12: Problems with semaphores - Signal/wait are primitive operations - Cannot impose discipline ** shared variables should not be accessed outside a Critical section ** Critical section should be correctly implemented
اسلاید 13: Problems with semaphores Process p0 Process p1 Wait (mutex) Signal(mutex) < CS > < CS > Signal (mutex) Wait (mutex)** Is this implementation of CS correct?
اسلاید 14: MonitorsMonitor is a software moduleChief characteristicsLocal data variables are accessible only by the monitorProcess enters monitor by invoking one of its proceduresOnly one process may be executing in the monitor at a time
اسلاید 15: Monitors -- Implements data abstraction ** arbitrary operations cannot be performed on monitor data-- Implements encapsulation for mutual exclusion ** Only one process can be in the monitor at any time
اسلاید 16: Monitors -- Provides condition variables for synchronization of processes condition notfull; .. Cwait(notfull); -- Process is blocked .. Csignal(notfull); -- A blocked process is activated
اسلاید 17: Bounded buffer Prod-Con using Monitors Prodcon: monitor buffer[..] /* shared data */ nextin, nextout, count: .. void Prod() /* Operations can manipulate shared data*/ void Cons() {nextin=0, … } /* Initializations */ void (producer) {… } void (consumer) {…} void main() { Parbegin(producer, consumer)}
اسلاید 18: Bounded buffer Prod-Con using Monitors void produce() void consume(){ While (count == N) { While (count==0) cwait(notfull); cwait(notempty); buffer[nextin]= .. X=buffer[nextout] nextin=nextin+1%N nextout=… count++ count-- csignal(notempty); csignal(notfull); } }
اسلاید 19:
اسلاید 20: Readers/Writers ProblemAny number of readers may simultaneously read the fileOnly one writer at a time may write to the fileIf a writer is writing to the file, no reader may read it
نقد و بررسی ها
هیچ نظری برای این پاورپوینت نوشته نشده است.