Chapter 5 Mutual Exclusion and Synchronization 5.1 Principles of Concurrency ·5.2 Mutua|EXc| usion 5.3 Semaphores 5. 4 Monitors 5.5 Message Passing 5.6 Readers /writers problem .5. Summary
2 Chapter 5 Mutual Exclusion and Synchronization • 5.1 Principles of Concurrency • 5.2 Mutual Exclusion • 5.3 Semaphores • 5.4 Monitors • 5.5 Message Passing • 5.6 Readers/Writers Problem • 5.7 Summary
Last Class: Semaphores A semaphore S supports two atomic operations SPO: get a semaphore, wait if busy semaphore s is available SVO: release the semaphore, wake up a process if one is waiting for s Types of semaphore Binary or Mutex Semaphore: grants mutual exclusive access to a resource Counting Semaphore: useful for granting mutually exclusive access for a set of resources Semaphores are difficult to use: orders are important
Last Class: Semaphores • A semaphore S supports two atomic operations • S→P(): get a semaphore, wait if busy semaphore S is available. • S→V(): release the semaphore, wake up a process if one is waiting for S. • Types of semaphore • Binary or Mutex Semaphore: grants mutual exclusive access to a resource • Counting Semaphore: useful for granting mutually exclusive access for a set of resources • Semaphores are difficult to use: orders are important 3
Solution higher level primitive oS codes and concurrent applications High-Level Mutex Semaphores Monitors Send/Recv Atomic API LoW-Level Load/store Interrupt Test& Set Other atomic Atomic Ops disable/enable instructions interrupts CPU (1/0, timer) Multiprocessors scheduling
Solution:higher level primitive 4
5.4 Monitors .5 4.1 Concept of monitors 5.4.2 Producer-Consumer with monitors
5.4 Monitors • 5.4.1 Concept of Monitors • 5.4.2 Producer-Consumer with Monitors 5
5.4.1 Concept of Monitors(1/10) Monitor(管程) A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process/thread may be executing in the monitor at a time
5.4.1 Concept of Monitors(1/10) • Monitor(管程) • A high-level abstraction that provides a convenient and effective mechanism for process synchronization. • Only one process/thread may be executing in the monitor at a time. 6