Semaphores (Avoiding Train Wrecks) Kevin O’Gorman CS April 2002
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = -1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = -1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = -1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. Success!
(continued…)
Semaphores Re-Run
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 1
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. sem = 0
Signalling. A1 statement A2 sem.signal(). B1 sem.wait() B2 statement. Success!