02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.

Slides:



Advertisements
Similar presentations
Chapter 6: Process Synchronization
Advertisements

02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Silberschatz, Galvin and Gagne  Operating System Concepts Background Shared-memory solution to bounded-buffer problem allows at most n – 1 items.
Synchronization Principles Gordon College Stephen Brinton.
1 Last Time: Locks & Semaphores Implementing locks Test & Set Busy waiting Block waiting Semaphores Generalization of locks.
6/12/2015Page 1 Inter-Process Communication and Synchronization B. Ramamurthy.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Process Synchronization
Monitors CSCI 444/544 Operating Systems Fall 2008.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
What we will cover… Process Synchronization Basic Concepts
02/11/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Monitors High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. monitor monitor-name {
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
5.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Problems with Semaphores Incorrect use of semaphore operations:
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Synchronization Background The Critical-Section.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Fall 2000M.B. Ibáñez Lecture 08 High Level mechanisms for process synchronization Critical Regions Monitors.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
7.1 Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
CSE Operating System Principles Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Operating Systems Unit 4: – Dining Philosophers – Deadlock – Indefinite postponement Operating Systems.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Deadlock and Starvation
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Process Synchronization: Semaphores
Chapter 5: Process Synchronization – Part 3
PARALLEL PROGRAM CHALLENGES
Chapter 5: Process Synchronization
Deadlock and Starvation
Chapter 7: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 6: Process Synchronization
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
Lecture 25 Syed Mansoor Sarwar
Semaphore Originally called P() and V() wait (S) { while S <= 0
Module 7a: Classic Synchronization
More IPC B.Ramamurthy 4/15/2019.
Lecture 26 Syed Mansoor Sarwar
Presentation transcript:

02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying an earlier version of the course text Operating Systems Concepts with Java, by Silberschatz, Galvin, and Gagne. Many, if not all, the illustrations contained in this presentation come from this source.

02/19/2010CSCI 315 Operating Systems Design2 Semaphore as General Synchronization Tool Counting semaphore – integer value can range over an unrestricted domain. Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement (also known as mutex locks). Note that one can implement a counting semaphore S as a binary semaphore. Provides mutual exclusion: Semaphore S(1); // initialized to 1 acquire(S); criticalSection(); release(S);

02/19/2010CSCI 315 Operating Systems Design3 Semaphore Implementation acquire(S) { value--; if (value < 0) { add this process to list block; } release(S) { value++; if (value <= 0) { remove some process P from list wakeup(P); }

02/19/2010CSCI 315 Operating Systems Design4 Semaphore Implementation Must guarantee that no two processes can execute acquire() and release() on the same semaphore at the same time. The implementation becomes the critical section problem: –Could now have busy waiting in critical section implementation But implementation code is short Little busy waiting if critical section rarely occupied –Applications may spend lots of time in critical section

02/19/2010CSCI 315 Operating Systems Design5 Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. Let S and Q be two semaphores initialized to 1 P 0 P 1 acquire(S); acquire(Q); acquire(Q); acquire(S);. release(S); release(Q); release(Q); release(S); Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended.

02/19/2010CSCI 315 Operating Systems Design6 The Dining-Philosophers Problem

02/19/2010CSCI 315 Operating Systems Design7 The Dining-Philosophers Problem thinking hungry eating State diagram for a philosopher Shared data: semaphore chopstick[5]; (Initially all values are 1)

02/19/2010CSCI 315 Operating Systems Design8 The Dining-Philosophers Problem Question: How many philosophers can eat at once? How can we generalize this answer for n philosophers and m chopsticks? Question: What happens if the programmer initializes the semaphores incorrectly? (Say, two semaphores start out a zero instead of one.) Question: How can we formulate a solution to the problem so that there is no deadlock or starvation?

02/19/2010CSCI 315 Operating Systems Design9 Dining-Philosophers Solution? Philosopher i do { wait(chopstick[i]) wait(chopstick[(i+1) % 5]) … eat … signal(chopstick[i]); signal(chopstick[(i+1) % 5]); … think … } while (1);

02/19/2010CSCI 315 Operating Systems Design10 Monitor Definition: High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. A procedure within a monitor can access only local variables defined within the monitor. There cannot be concurrent access to procedures within the monitor (only one thread can be active in the monitor at any given time). Condition variables: queues are associated with variables. Primitives for synchronization are wait and signal. monitor monitor-name { shared variables procedure body P1 (…) {... } procedure body P2 (…) {... } procedure body Pn (…) {... } { initialization code }

02/19/2010CSCI 315 Operating Systems Design11 Schematic View of a Monitor

02/19/2010CSCI 315 Operating Systems Design12 Monitor To allow a process to wait within the monitor, a condition variable must be declared, as condition x, y; Condition variable can only be used with the operations wait and signal. –The operation x.wait(); means that the process invoking this operation is suspended until another process invokes x.signal(); –The x.signal operation resumes exactly one suspended process. If no process is suspended, then the signal operation has no effect.

02/19/2010CSCI 315 Operating Systems Design13 Monitor and Condition Variables

02/19/2010CSCI 315 Operating Systems Design14 Dining Philosophers with Monitor monitor dp { enum {thinking, hungry, eating} state[5]; condition self[5]; void pickup(int i); void putdown(int i); void test(int i); void init() { for (int i = 0; i < 5; i++) state[i] = thinking; }

02/19/2010CSCI 315 Operating Systems Design15 Dining Philosophers void pickup(int i) { state[i] = hungry; test(i); if (state[i] != eating) self[i].wait(); } void putdown(int i) { state[i] = thinking; /* test left and right neighbors */ test((i+4) % 5); test((i+1) % 5); } void test(int i) { if ( (state[(i + 4) % 5] != eating) && (state[i] == hungry) && (state[(i + 1) % 5] != eating)) { state[i] = eating; self[i].signal(); }