/
Chapter 5 Concurrency: Chapter 5 Concurrency:

Chapter 5 Concurrency: - PowerPoint Presentation

pasty-toler
pasty-toler . @pasty-toler
Follow
343 views
Uploaded On 2019-12-18

Chapter 5 Concurrency: - PPT Presentation

Chapter 5 Concurrency Mutual Exclusion and Synchronization C Threading BYU CS 345 State Change in C The setjmp longjmp set of macros implemented in the C provide the perfect platform to perform complex ID: 770863

wait semaphore exclusion signal semaphore wait signal exclusion task byu mutual context state queue return tid tcb ready int

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Chapter 5 Concurrency:" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Chapter 5Concurrency:Mutual Exclusion andSynchronization

C Threading

BYU CS 345State Change in C The setjmp / longjmp set of macros implemented in the C provide the perfect platform to perform complex flow-control.The setjmp function saves the state of a program in a jmpbuf array.The state of a program are the register values, sp (stack pointer), fp (frame pointer), and pc (program counter).Executing a setjmp always returns 0 after saving the stack environment.Executing a longjmp jumps to a setjmp which then returns the value of the argument of the longjmp (0 is never returned).A call to longjmp restores the saved environment and returns control to the point just after the corresponding setjmp call. C Threads Mutual Exclusion

BYU CS 345setjmp / longjmp #include < setjmp.h > jmp_buf An array capable of storing minimal CPU context ( ie, stack pointer (sp), frame pointer (fp), and program counter (pc)). Contents are intentionally meaningless.setjmp(jmp_buf env);saves the register contents, (ie, program state, sp, fp, pc) in a jmp_buf array (env) so that the function longjmp()can restore them later.returns 0 value.longjmp(jmp_buf env, int val ); resets the registers to the values saved in env.longjmp() returns as if you have just called the setjmp() call that saved env with non-zero value. setjmp/longjmp Mutual Exclusion

Repeat 4 times jmp_buf k_context ; int tid ;struct{ ... void* stackEnd ; jmp_buf context;} tcb[4]; void myThread () // my thread { while (1) { if(!setjmp(tcb[tid].context)) longjmp(k_context,2); // body of thread }} Switch to thread stack BYU CS 345 Multi-threading in C setjmp /longjmp // new threadsfor (tid = 0; tid < 4; tid++){ if (setjmp(k_context) == 0) { temp = (int*)tcb[tid].stackEnd; SET_STACK(temp); if (setjmp(tcb[tid].context) == 0) { longjmp(k_context, 1); } myThread(); }}while (1) // schedule threads{ tid = scheduler(); if (setjmp(k_context) == 0) { longjmp(tcb[tid].context, 3); }} Mutual Exclusion Save Context Save Context Save Context Save Context Restore Context Return 3 Restore Context Return 2 Restore Context Return 1 Restore Context Return 3 Start Here Enter Scheduler Restore Context Return 3 Save Context Return 0 Return 0 Return 0 Return 0 Return 0 SWAP;

BYU CS 345Multi-tasking in C setjmp / longjmp Mutual Exclusion SWAP;

BYU CS 345Multi-tasking in C setjmp / longjmp Mutual Exclusion // new curTaskif ((code = setjmp(k_context)) == 0){ // change stack pointer to temp temp = (int*)tcb[curTask].stackEnd; SET_STACK(temp) } // scheduler while (1) { if (code == 1) return ; curTask = scheduler(); // save kernel state in k_context if ((code = setjmp(k_context)) == 0) { // restore user context / resume task longjmp(tcb[curTask].context, 3) }} int newTask(int argc , char* argv){ while (1) { // save user context in tcb if (!setjmp(tcb[curTask].context) { // restore kernel context longjmp( k_context, 2); } // ... { return 0;} // begin execution of new task result = (*tcb[curTask].task) (tcb[curTask].argc, tcb[curTask].argv); longjmp(k_context), 1);

BYU CS 345 CS 345 Stalling’s Chapter # Project 1: Computer System Overview 2: Operating System Overview 4P1: Shell3: Process Description and Control4: Threads 4 P2: Tasking 5: Concurrency: ME and Synchronization 6: Concurrency: Deadlock and Starvation 6P3: Jurassic Park7: Memory Management8: Virtual memory6P4: Virtual Memory9: Uniprocessor Scheduling10: Multiprocessor and Real-Time Scheduling 6 P5: Scheduling 11: I/O Management and Disk Scheduling 12: File Management 8P6: FATStudent Presentations6Mutual Exclusion

Chapter 5 Learning ObjectivesDiscuss basic concepts related to concurrency, such as race conditions, OS concerns, and mutual exclusion requirements. Understand hardware approaches to supporting mutual exclusion. Define and explain semaphores. Define and explain monitors. Explain Producer/Consumer Bounded bufferReaders/writers problemClassical synchronization problemsBYU CS 345Mutual Exclusion

BYU CS 345Review… The OS must keep track of active processes. The OS must allocate and deallocate resources. Processor time Memory Files I/O devicesThe OS must protect the data and physical resources.The results of a process must be independent of the speed of execution relative to the speed of other concurrent processes.Mutual ExclusionMutual Exclusion

CooperationA cooperating process is one that can affect or be affected by other processes executing in the system. A race condition occurs when the outcome depends on the particular order of execution, most often associated with shared resources. Share logical space (threads) Files or messagesConcurrent or parallel executionMutual exclusion prevents race conditions by synchronizing resource access.BYU CS 345Mutual Exclusion

BYU CS 345Resource Allocation Shared resources are Produced Consumed Resource sharing presents problems of Mutual ExclusionCritical resource – a single nonsharable resource.Critical section – portion of the program that accesses a critical resource.DeadlockEach process owns a resource that the other is waiting for.Two processes are waiting for communication from the other.StarvationA process is denied access to a resource, even though there is no deadlock situation.Mutual Exclusion

BYU CS 345 The Producer-Consumer Problem repeat … produce an item in nextp … while (counter == n); buffer[in] = nextp in = (in + 1) mod n counter = counter + 1 until false Producer repeat … while (counter == 0); nextc = buffer[out] out = (out + 1) mod n counter = counter - 1 … consume the item in nextc …until false Consumer Producer/Consumer Is there anything wrong here? Shared variables: buffer[], counter = 0, n = 128;Mutual ExclusionYes, possible race condition!

BYU CS 345Consider… P0 : wait(S); wait(Q); ... signal(S); signal(Q); P1 : wait(Q); wait(S); ... signal(Q ); signal(S); Is there anything wrong here?Semaphores Shared variables: S = Q = 1; Mutual Exclusion Yes, possible deadlock!

BYU CS 345Consider… P0 : Enter classroom; Occupy seat; Take exam; Turnoff lights; Semaphores P1 : Enter classroom; Occupy seat; Take exam; Turnoff lights; P2 : ... Mutual Exclusion Is there anything wrong here? Yes, possible indeterminate results!

BYU CS 345Semaphores What is a semaphore ? A semaphore is an autonomous synchronous abstract data type used for controlling access by multiple processes, to a common resource in a concurrent system.How are semaphores produced?Semaphores are produced by SEM_SIGNAL.How are semaphores consumed?Semaphores are consumed by SEM_WAIT and SEM_TRYLOCK.What are the major uses of semaphores?SynchronizationResource allocationMutual Exclusion SemaphoresMutual Exclusion

BYU CS 224 Threads 17 Semaphores A semaphore is a protected variable whose value is accessed and altered by the operations signal (produce) and wait (consume).A semaphore is used for controlling access to a common resource in a concurrent system, such as multi-threading.The value of a semaphore is the number of available resources and may be used to synchronize various task activities. A useful way to think of a semaphore is as a record of how many units of a particular resource are available, coupled with operations to safely consume those units, and, if necessary, wait until a unit of the resource becomes available.

BYU CS 224 Threads 18 Mutexes A mutex is locking mechanism used to synchronize access to a resource (such as code).Only one task can acquire the mutex.It means there is ownership associated with mutex, and only the owner can release the lock (mutex).A mutex is designed to protect critical data so that only one thread can access it at the same time, such as a section of code or access to a variable.

BYU CS 345Semaphores What does it mean to be autonomous? Disable interrupts (only works on uni -processor) Hardware: test-and-set, exchange Software solutions (Decker)What does it mean to be synchronous?What are the different types of semaphores?Binary semaphore – 1 resource, 2 states0 = nothing produced, maybe tasks in queue1 = something produced, no tasks in queueCounting semaphore – 1 resource, multiple copies0 = nothing produced, nothing in queue-n = nothing produced, n tasks queued+n = n items produced, no tasks in queueSemaphoresMutual Exclusion

BYU CS 345SEM_SIGNAL - Producer Semaphores void semSignalBinary (Semaphore* semaphore) // signal binary semaphore { semaphore->state = 1; // produce (signal) binary semaphore tid = deQ (semaphore->queue, - 1); // dequeue blocked task if (tid < 0) return; // if empty, return semaphore->state = 0; // blocked task consumes semaphore tcb[tid].state = S_READY; // ready task for execution enQ(rq, tid, tcb[tid].priority); // move task to ready queue return;} // end semSignalBinary void semSignalCounting (Semaphore* semaphore) // signal counting semaphore { if (++semaphore->state > 0) return; // return if nothing in queue tid = deQ(semaphore->queue, -1); // dequeue task tcb[tid].state = S_READY; // ready task for execution enQ(rq, tid, tcb[tid].priority); // move task to ready queue return;} // end semSignalCountingProduceConsumeProduce & ConsumeMutual Exclusion

BYU CS 345SEM_WAIT - Consumer Semaphores void semWaitBinary (Semaphore* semaphore) // wait binary semaphore { if (semaphore->state == 0) // signaled? { tcb [ curTask ].state = S_BLOCKED; // n, change task state to blocked enQ(semaphore->queue, deQ(rq, curTask));// move from ready to blocked queue swapTask(); // reschedule the tasks } semaphore->state = 0; // consume semaphore return; // return w/no block} // end semWaitBinary void semWaitCounting (Semaphore* semaphore) // wait counting semaphore { semaphore->state--; // consume if (semaphore->state < 0) { tcb[curTask].state = S_BLOCKED; // change task state to blocked enQ(semaphore->queue, deQ(rq, curTask));// move from ready to blocked quueu swapTask(); // reschedule the tasks } return; // return w/semaphore} // end semWaitCountingMutual Exclusion

Step 3: 5-State SchedulingBYU CS 345 Add priority queue to semaphore struct typedef struct semaphore // semaphore { struct semaphore* semLink; // link to next semaphore char* name; // semaphore name (malloc) int state; // state (count) int type; // type (binary/counting) int taskNum; // tid of creator PQueue q; // blocked queue } Semaphore;Malloc semaphore queue in createSemaphore semaphore->q = (int*) malloc ((MAX_TASKS + 1) * sizeof(int)); semaphore->q[0] = 0; // init queue semWait: deQueue current task from ready queue and enQueue in semaphore block queuesemSignal: deQueue task from semaphore block queue and enQueue in ready queue. Project 2 Assignment Mutual Exclusion

Blocked Queues semWait() 5-State Scheduler BYU CS 345 createTask() d ispatch() swapTask() killTask() New Ready Queue Running Exit # define SWAP swapTask (); # define SEM_WAIT(s ) semWait (s );#define SEM_SIGNAL(s) semSignal(s);#define SEM_TRYLOCK(s) semTryLock(s);P2 - TaskingsemSignal()Mutual Exclusion

BYU CS 345Task Scheduling Ready Priority Queue Semaphore Priority Queue Semaphore Priority Queue Semaphore Priority Queue … SWAP SEM_SIGNAL SEM_WAIT SEM_SIGNAL SEM_WAIT SEM_SIGNAL SEM_WAIT Executing Scheduler / Dispatcher Scheduling Mutual Exclusion

Step 4a: Counting SemaphoreBYU CS 345 Add counting functionality to semaphores os345semaphores.c: semSignal, semWait, semTryLock Replace goto temp; Add a 10 second timer (tics10sec) counting semaphore to the polling routine (os345interrupts.c).#include <time.h> header.Call the C function time(time_t *timer).semSignal the tics10sec semaphore every 10 seconds.Create a reentrant high priority timing task thatblocks (SEM_WAIT) on the 10 second timer semaphore (tics10sec).when activated, outputs a message with the current task number and time and then blocks again. Project 2 AssignmentMutual Exclusion

BYU CS 345Task Control Block (tcb) P2 - Tasking // task control block typedef struct // task control block{ char* name; // task name int (*task)(int,char**); // task address int state; // task state (P2) int priority; // task priority (P2 ) int argc; // task argument count (P1) char** argv; // task argument pointers (P1) int signal; // task signals (P1)// void (*sigContHandler)(void); // task mySIGCONT handler void (*sigIntHandler)(void); // task mySIGINT handler // void (*sigKillHandler)(void); // task mySIGKILL handler // void (*sigTermHandler)(void); // task mySIGTERM handler // void (* sigTstpHandler)(void); // task mySIGTSTP handler TID parent; // task parent int RPT; // task root page table (P4) int cdir; // task directory (P6) Semaphore *event; // blocked task semaphore (P2) void* stack; // task stack (P1) jmp_buf context; // task context pointer (P1)} TCB;State = { NEW, READY, RUNNING, BLOCKED, EXIT }Priority = { LOW, MED, HIGH, VERY_HIGH, HIGHEST }Pending semaphore when blocked.Mutual Exclusion

Step 4b: List TasksBYU CS 345 Modify the list tasks command to Display all tasks in all system queues in execution/priority orderList task name, if the task is ready, paused, executing, or blocked, and the task priority.If the task is blocked, list the reason for the block.Use the project2 command to schedule timer tasks 1 through 9, 2 signal tasks and 2 “ImAlive” tasks.The tics10sec task about the current time every 10 seconds in a round robin order. (Round Robin)The “ImAlive” tasks will periodically say hello. (Blocking)The high priority “Signal” tasks should respond immediately when semaphore signaled. (Priority) Project 2 AssignmentMutual Exclusion

Step 4c: VerificationBYU CS 345 Demo # Task Name Priority Time slice Blocking Semaphore 0 CLI w/pseudo-input interrupts 5 1 inBufferReady 1-9 TenSeconds 10 1 tics10sec 10 sTask1 20 1 sTask10 11 sTask2 20 1 sTask11 12 ImAlive 1 1 None 13 ImAlive 1 1 None Project 2 Assignment Mutual Exclusion

BYU CS 345Bounded Buffer Solution repeat produce an item in nextp wait(empty); wait(mutex); add nextp to the buffer signal(mutex); signal(full);until false repeat wait(full); wait(mutex); remove an item from buffer place it in nextc signal(mutex); signal(empty); consume the item in nextcuntil falseShared semaphore: empty = n, full = 0, mutex = 1;Bounded Buffer Mutual Exclusion

BYU CS 345Readers and Writers Problem Data object is shared (file, memory, registers) many processes that only read data (readers) many processes that only write data (writers) Conditions needing to be satisfied:many can read at the same time (patron of library)only one writer at a time (librarian)no one allowed to read while someone is writingDifferent from producer/consumer (general case with mutual exclusion of critical section) – possible for more efficient solution if only writers write and readers read.Solutions result in reader or writer priorityReader/WriterMutual Exclusion

BYU CS 345Shared Data What are some characteristics of shared data objects (files, data bases, critical code)? Many processes only need mutual exclusion of critical sections (producer/consumer, mutexes ) many processes only read data (readers) many processes only write data (writers)What conditions / advantages / problems arise when there is concurrent reading and writing?many can read at the same time (patrons of library)only one writer at a time (librarians)no one allowed to read while someone is writingpossible for more efficient solution than producer / consumer if only writers write and readers read.Who should have priority, readers or writers? Reader/WriterMutual Exclusion

Who has priority Reader or Writer? BYU CS 345 Readers/Writers Semaphore rmutex=1, wmutex = 1; integer readcount = 0; Only one writer at a time More than one reader at a time The first reader makes sure no one can write Last one out allows writing again Readers have priority! (writers subject to starvation!) Reader/Writer while(true) { wait(wmutex); <write to the data object> signal(wmutex); }; Writer  while(true) { wait(rmutex); readcount++; if (readcount == 1) wait( wmutex); signal(rmutex); <read the data> wait(rmutex); readcount--; if (readcount == 0) signal(wmutex); signal(rmutex);};Reader Mutual Exclusion

BYU CS 345Writers/Readers while(true) { wait(outerQ); wait(rsem); wait(rmutex); readcnt++ if (readcnt == 1) wait(wsem); signal(rmutex); signal(rsem); signal(outerQ); READ wait(rmutex); readcnt--; if(readcnt == 0) signal(wsem); signal(rmutex); };while(true) { wait(wmutex); writecnt++; if (writecnt == 1) wait(rsem); signal(wmutex); wait(wsem); WRITE signal(wsem); wait(wmutex); writecnt--; if (writecnt == 0) signal(rsem); signal(wmutex);};Semaphore outerQ, rsem, rmutex, wmutex, wsem = 1; Additional readers queue here allowing writers to jump ahead of the readers Disable writers Last reader out allows writers Last writer out allows readers Wait here until all readers done, as well as multiple writersReader/WriterOnce a writer wants to write – no new readers allowedMutual Exclusion

BYU CS 345Barbershop Problem 3 barbers, each with a barber chair Haircuts vary in time Sofa can hold 4 customers Maximum of 20 in shop Customers arrive randomlyCustomers wait outside if necessaryWhen a chair is empty:Customer sitting longest on sofa is servedCustomer standing the longest sits downAfter haircut, customer pays cashier at cash registerBarbers have to cut hair and cashierCustomer waits for receiptUpon exit, new customer allowed in shop Entrance Standing room area Sofa Barber chairs Cashier Exit Barbershop Mutual Exclusion

BYU CS 345Fair Barbershop procedure customer; var custnr : integer;begin wait ( max_capacity ); // enter_shop wait( mutex1 ); count := count + 1; custnr := count; signal( mutex1 ); wait( sofa ); // sit on sofa wait( barber_chair ); // get up from sofa signal( sofa ); // sit in barber chair wait( mutex2 ); enqueue1( custnr ); signal( cust_ready ); signal( mutex2 ); wait( finished[custnr] ); // leave barber chair signal( leave_b_chair ); // pay signal( payment ); wait( receipt ); // exit shop signal( max_capacity ); end; Barbershop Entrance Standing room area SofaBarber chairsCashierExit procedure barber ; var b_cust : integer begin repeat // get customer wait ( cust_ready ); wait( mutex2 ); dequeue1 ( b_cust ); signal( mutex2 ); wait( coord ); // cut hair signal( coord ); signal( finished[b_cust] ); wait( leave_b_chair ); signal( barber_chair ); foreverend; procedure cashier;begin repeat wait( payment ); wait( coord ); // accept payment signal ( coord ); signal( receipt ); forever end; max_capacity: semaphore (:=20); sofa: semaphore (:=4); barber_chair, coord: semaphore (:=3);mutex1, mutex2 : semaphore (:=1);cust_ready, leave_b_chair: semaphore (:= 0)payment, receipt: semaphore (:=0)finished: array [1..50] of semaphore (:=0);count: integer; Mutual Exclusion

BYU CS 345 Visitors try to enter the Jurassic Park at random times. (Only a set number of visitors may be in the park at any one time – OSHA requirements!) Jurassic Park Upon being allowed in the park, a visitor must get in line to purchase a ticket. After successfully obtaining a ticket from a driver , the visitor gets in the museum line and visits the museum. (A limited number of visitors are allowed in the museum as well as the gift shop.) After visiting the museum, the visitor gets in the tour car line to wait until permitted to board a tour car. (As a visitor boards a tour car, he returns his ticket.) When the touring car is filled with visitors and a driver is obtained, the car enters Jurassic Park and runs a guided tour through the park. When the tour car pulls into the unloading station, the visitors exit the tour car. and the driver goes to sleep awaiting new duties. The tour car pulls forward to be loaded again. After visiting the gift shop, the visitors exit the park. After the visitors exit a tour car, they get into the gift shop line until they can visit the gift shop. Mutual Exclusion

BYU CS 345Jurassic Park procedure visitor; var visitor_id : integer;begin wait ( max_capacity ); // enter_park wait ( parkMutex ); numOutsidePark --; numInPark-++; signal ( parkMutex ); // get a ticket wait ( requestTicketMutex ); signal ( needTicket ); signal ( wakeupDriver ); wait ( takeTicket ); signal ( requestTicketMutex ); // visit museum // get in car line // wait for a seat wait ( need_visitor ); signal ( visitor_ready ); pass_to_car ( visitor_id ); wait ( ride_over ); // give back ticket // visit gift shop // exit park signal ( max_capacity );end;procedure car;var carID: integerbegin repeat // fill 3 car seats for (NUM_SEATS) { wait ( fillSeat[carID] ); signal ( need_visitor ); wait ( visitor_ready ); save_Visitor( visitorID ); signal ( seatFilled[carID] ); } pass_to_park( carDone ); signal ( carReady ); // enjoy ride wait ( carDone ); signal ( each visitorID ); foreverend;Mutual Exclusionmax_capacity : semaphore (:=20);parkMutex, requestTicketMutex : semaphore (:=1);needTicket , waitTicket: semaphore (:=0) procedure driver; var carID : integer begin repeat wait ( wakeupDriver ); if ( trylock ( need_ticket ) ) { signal (takeTicket); } else { signal ( driver_ready ); wait ( ride_over ); { foreverend;

BYU CS 345Message Passing Shared memory is useful in a threaded environment Single atomic variables (semaphores, modes) Memory mapping (data structures, messages) Test-and-set (atomic instructions) Fast – do not require data movement (reference)Inter-process communication (IPC) used by processesfor processes inside the same computerfor processes in a distributed systemMessage passing used by distributed systems (networks)send(destination, message)post(destination, message)receive(source, message)Message PassingMutual Exclusion

BYU CS 345Synchronization For the sender: it is more natural not to be blocked can send several messages to multiple destinations sender usually expects acknowledgment of message receipt (in case receiver fails) PostMessage () is asynchronous – returns immediately SendMessage() is synchronous –block until message delivered and processedFor the receiver: it is more natural to be blocked after issuing ReceiveMessage()the receiver usually needs the info before proceedingbut could be blocked indefinitely if sender process fails before sending replyMessage PassingMutual Exclusion

BYU CS 345Addressing Direct addressing: when a specific process identifier is used for source/destination but it might be impossible to specify the source ahead of time (ex: a print server) Indirect addressing (more convenient): messages are sent to a shared mailbox which consists of a queue of messagessenders place messages in the mailbox, receivers pick them upMessage PassingMutual Exclusion

BYU CS 345 Mailboxes and Ports A mailbox can be private one sender/receiver pair A mailbox can be shared among several senders and receivers OS may then allow the use of message types (for selection) Port: a mailbox associated with one receiver and multiple sendersused for client/server application: the receiver is the server Message PassingMutual Exclusion

BYU CS 345Port/Mailbox Ownership A port is usually owned and created by the receiving process The port is destroyed when the receiver terminates The OS creates a mailbox on behalf of a process (which becomes the owner) The mailbox is destroyed at the owner’s request or when the owner terminates Message Passing Mutual Exclusion

BYU CS 345 Monitors A programming-language construct that provides equivalent functionality to that of semaphores ME threads that wait (block) for true conditions. Thread-safe class (wrapped by mutual exclusive conditions) Concurrent Pascal, Pascal-Plus, Modula, JavaA monitor is a software module containing:one or more procedures, an initialization sequence, and local data variablesMutex (lock) object and condition variablesCondition variable:Container of threads that are waiting on a certain condition.Threads temporarily give up exclusive access in order to wait for some condition to be met.Local variables accessible only by monitor’s proceduresA process enters the monitor by invoking one of its proceduresOnly one process can be in the monitor at any one time Monitor Mutual Exclusion

BYU CS 345 Monitor boundedbuffer : buffer: array[0..k-1] of items ; nextin:=0, nextout:=0, count:=0: integer; notfull, notempty: condition; Produce(v): if (count = k) cwait(notfull); buffer[nextin] := v; nextin := nextin+1 mod k; count++; csignal( notempty); Consume(v): if (count = 0) cwait(notempty ) ; v := buffer[ nextout ]; nextout := nextout+1 mod k; count--; csignal(notfull); Monitor for the P/C problemMonitorMake threading systemrelease all locks andsleep until condition is met. Signal a consumer thread o r all consumer threadsthat are blocked waiting for n on-empty buffer .Mutual Exclusion

BYU CS 345Conclusion Semaphores are a powerful tool for enforcing mutual exclusion and to coordinate processes. When wait(S ) and signal(S) are scattered among several processes Difficult to understand their effects.Difficult to test.Monitors make classes thread-safe and mutual exclusion more controllable.Usage must be correct in all the processes (everyone has to play by the rules).One bad (or malicious) process can fail the entire collection of processesConclusionMutual Exclusion

BYU CS 345 Mutual Exclusion