OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Chapter 2 Processes (part 2) Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 How To Prove Mutual Exclusion • Mutual Exclusion Properties: – – – – No deadlock: the two processes cannot enter a state where they simultaneously wait for each other No livelock: if the two processes execute, one of them at least progresses to the critical section Fairness/Absence of starvation: if one process requests the privilege to enter the critical section, it eventually enters the critical section Correctness: two processes cannot enter the critical section simultaneously Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 1 Finite Automata A Simple Automaton Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Synchronized Product A=BxC Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 2 Synchronized Product Set of Synchronization: all actions wearing the same label Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Automata to Model Interleaving Executions (pseudo-parallelism) int B; 1: B = 0; 2: while(!B) { 3: B = 1; 4: proc(); 5: B = 0; 6: } Properties: - proc() is called infinitely often - when proc() is called, B = 1. Assumption: - proc() does not modify B. 7: exit() Example of program and property to check Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 3 Model Through Automaton Model of a boolean variable Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Modelization Through Automaton Model of the Simple Program Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 4 Modelization Through Automaton Model of the system (synchronized product of program + variables) Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Proof of TSL (2 processes) See start of this on whiteboard Complete it as an exercise Synchronized Product of a lock + two processes with Test and Set Lock Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 5 The Producer-Consumer Problem (1) ... Figure 2-13. The producer-consumer problem with a fatal race condition. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 The Producer-Consumer Problem (2) ... Figure 2-13. The producer-consumer problem with a fatal race condition Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 6 Semaphores sem_t s -> delcares a semaphore down(s) -> decrease the value. If value already 0, block until value > 0. up(s) -> increase the value. sem_init(s, i) -> initialize the value to i (sem_get(s)) -> optional, gives the current value Routines of Semaphores Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 The Producer-Consumer Problem (3) ... Figure 2-14. The producer-consumer problem using semaphores. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 7 The Producer-Consumer Problem (4) ... Figure 2-14. The producer-consumer problem using semaphores. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Monitors (1) Figure 2-15. A monitor. Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 8 Monitors (2) Figure 2-16. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 Monitors (3) Figure 2-16. An outline of the producer-consumer problem with monitors. Only one monitor procedure at a time is active. The buffer has N slots Tanenbaum & Woodhull, Operating Systems: Design and Implementation, (c) 2006 Prentice-Hall, Inc. All rights reserved. 0-13-142938-8 9
© Copyright 2024