5.3.1 What is semaphore? (9/10 Semaphore terms(信号量术语) Counting Semaphore(计数信号量)/ General Semaphore(一般信号量) · Binary Semaphore(二元信号量) Mutex(互斥信号量 Weak Semaphore(弱信号量) Strong Semaphore(强信号量)
12 • Semaphore terms (信号量术语) • Counting Semaphore (计数信号量)/ General Semaphore(一般信号量) • Binary Semaphore (二元信号量) • Mutex (互斥信号量) • Weak Semaphore(弱信号量) • Strong Semaphore(强信号量) 5.3.1 What is semaphore?(9/10)
5.3.1 What is semaphore? (10/10) Strong/Weak semaphore a queue is used to hold processes waiting on the semaphore Strong Semaphores the process that has been blocked the longest is released from the queue first FiFo) Weak semaphores the order in which processes are removed from the queue is not specified
5.3.1 What is semaphore?(10/10) • Strong/Weak Semaphore • A queue is used to hold processes waiting on the semaphore 13
5.3 Semaphores 5.3.1 What is semaphore? 5.3.2 Two Uses of Semaphores 5.3.3 Producer/consumer problem 5.3.4 Implement of Semaphores .5.3.5 Semaphore in UNIX
14 5.3 Semaphores • 5.3.1 What is semaphore? • 5.3.2 Two Uses of Semaphores • 5.3.3 Producer/Consumer Problem • 5.3.4 Implement of Semaphores • 5.3.5 Semaphore in UNIX
5.3.2 Two Uses of Semaphores(1/18 ·1. Mutua|exc| usIon Lock was designed to do this lock->acquire l/ critical section lock->release 15
5.3.2 Two Uses of Semaphores(1/18) • 1. Mutual exclusion • Lock was designed to do this 15 lock->acquire(); // critical section lock->release();
5.3.2 Two Uses of Semaphores(2/18 Mutual Exclusion with a binary semaphore program mutualexclusion * const int n =/ number of processes */i semaphore s=1i Semaphore has an initial void P(int 1) value of 1 while (true) semWait(s)i PO is called before a / critical section semsignal(s)i critical section / remainder vO is called after the void main o critical section parbegin (P(1), P(2), Figure 5.6 Mutual Exclusion Using Semaphores
5.3.2 Two Uses of Semaphores(2/18) • Mutual Exclusion with a binary semaphore 16 Semaphore has an initial value of 1 P() is called before a critical section V() is called after the critical section