Process Synchronization Monitors Simulation of Monitors Checkpoint and Recovery Monitors Simulation of Monitors Checkpoint and Recovery Topics:

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.
Chapter 6 Process Synchronization: Part 2. Problems with Semaphores Correct use of semaphore operations may not be easy: –Suppose semaphore variable called.
Process Synchronization CS 3100 Process Synchronizatiion1.
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/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6: Process Synchronization.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Critical Regions § 7.6 Although semaphores provide a convenient and effective mechanism for process synchronization, their incorrect use can still result.
Process Synchronization
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
6: Process Synchonization II 1 PROCESS SYNCHRONIZATION II THE BOUNDED BUFFER ( PRODUCER / CONSUMER ) PROBLEM: This is the same producer / consumer problem.
Modified from Silberschatz, Galvin and Gagne & Stallings Lecture 12 Chapter 6: Process Synchronization (cont)
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Solution to Dining Philosophers. Each philosopher I invokes the operations pickup() and putdown() in the following sequence: dp.pickup(i) EAT dp.putdown(i)
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Monitors High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. monitor monitor-name {
UNIT III: Concurrency Process SynchronizationSynchronization The Critical-Section problemCritical-Section problem Peterson’s Solution Synchronization HardwareHardware.
Chapter 6: Process Synchronization Adapted to COP4610 by Robert van Engelen.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Module 6: Synchronization Background The Critical-Section.
7c.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Module 7c: Atomicity Atomic Transactions Log-based Recovery Checkpoints Concurrent.
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 – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Outline n Background.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: 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.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Synchronization. 6.2Operating System Principles Module 6: Synchronization Background The Critical-Section Problem Peterson’s Solution 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.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 6 Operating Systems.
Chapter 6: Process Synchronization. 6.2 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution 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.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Chapter 6: Process Synchronization. 6.2CSCI 380 – Operating Systems Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
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.
1 Advanced Operating Systems - Fall 2009 Lecture 7 – February 2, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Module 6: Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Deadlock and Starvation
Chapter 6: Process Synchronization
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Chapter 5: Process Synchronization
Deadlock and Starvation
Chapter 6-7: Process Synchronization
Advanced Operating Systems - Fall 2009 Lecture 8 – Wednesday February 4, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours: M,
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Module 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Synchronization
Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Chapter 6: Process Synchronization
Presentation transcript:

Process Synchronization Monitors Simulation of Monitors Checkpoint and Recovery Monitors Simulation of Monitors Checkpoint and Recovery Topics:

Monitors High -level synchronization construct that allows the safe sharing of an abstract data-type using concurrent processes class monitor-name { variable declarations method declarations initialization } High -level synchronization construct that allows the safe sharing of an abstract data-type using concurrent processes class monitor-name { variable declarations method declarations initialization }

Monitors (continued) To allow a process to wait within a monitor a condition variable must be declared as condition x,y; The operation x.wait means that the process invoking the command waits (outside the monitor) The operation x.signal resumes exactly one suspended process. To allow a process to wait within a monitor a condition variable must be declared as condition x,y; The operation x.wait means that the process invoking the command waits (outside the monitor) The operation x.signal resumes exactly one suspended process.

Dining Philosopher Example monitor dining_philosopher { int state[5] /*thinking,hungry and eating */ condition self[5]; method pickup(int I) {state[I]=hungry;test(I); if (state[I]<>eating) self[I].wait(); } method putdown(int I) { state[I]=thinking;test( (I-1)%5);test((I+1)%5);} monitor dining_philosopher { int state[5] /*thinking,hungry and eating */ condition self[5]; method pickup(int I) {state[I]=hungry;test(I); if (state[I]<>eating) self[I].wait(); } method putdown(int I) { state[I]=thinking;test( (I-1)%5);test((I+1)%5);}

Dining Philosopher Example (continued) Method test(int k) { if (state[(k-1)%5] <> eating and state[k]==hungry and state[(k+1)%5]<>eating) {state[k]=eating;self[k].signal;} Method init { for (I=0;I<5;I++) state[I]=thinking;} Method test(int k) { if (state[(k-1)%5] <> eating and state[k]==hungry and state[(k+1)%5]<>eating) {state[k]=eating;self[k].signal;} Method init { for (I=0;I<5;I++) state[I]=thinking;}

Property of Monitor - At most one process is inside the monitor - We need to have mutual exclusion inside a monitor. - When a process is blocked, it is made to wait outside the monitor. - No process is assumed to die inside a monitor. - At most one process is inside the monitor - We need to have mutual exclusion inside a monitor. - When a process is blocked, it is made to wait outside the monitor. - No process is assumed to die inside a monitor.

Monitor Implementation Using Semaphore Variables: Semaphore mutex(=1),next(=0); int next-count(=0); Each method F (inside a monitor will be replaced by: wait(mutex); F; if (next-count>0) signal(next); else signal(mutex); Mutual Exclusion within a monitor is ensured Variables: Semaphore mutex(=1),next(=0); int next-count(=0); Each method F (inside a monitor will be replaced by: wait(mutex); F; if (next-count>0) signal(next); else signal(mutex); Mutual Exclusion within a monitor is ensured

Monitor Implementation Using Semaphore For each condition variable x, we have: Semaphore x-sem(=0);int x-count(=0); The operation x.wait can be implemented as: x-count++; if (next-count > 0) signal(next) else signal(mutex); wait(x-sem);x-count--; Value of priority stored with the name of the process that is suspended. For each condition variable x, we have: Semaphore x-sem(=0);int x-count(=0); The operation x.wait can be implemented as: x-count++; if (next-count > 0) signal(next) else signal(mutex); wait(x-sem);x-count--; Value of priority stored with the name of the process that is suspended.

Solaris 2 Operating System Implements a variety of locks to support multitasking, multithreading (including real-time threads), and multiprocessing. Uses adaptive mutexes for efficiency when protecting data from short-code segments Uses condition variables and readers- writers locks when longer sections of code need to access data. Implements a variety of locks to support multitasking, multithreading (including real-time threads), and multiprocessing. Uses adaptive mutexes for efficiency when protecting data from short-code segments Uses condition variables and readers- writers locks when longer sections of code need to access data.

Atomic Transactions Transaction - program unit that must be executed atomically; i.e., either all the operations associated with it are executed to completion or none are performed. Must preserve atomicity despite possibility of failure. Ensuring atomicity in an environment where failures result in the loss of information on volatile storage. Transaction - program unit that must be executed atomically; i.e., either all the operations associated with it are executed to completion or none are performed. Must preserve atomicity despite possibility of failure. Ensuring atomicity in an environment where failures result in the loss of information on volatile storage.

Log-Based Recovery Write-ahead log - all updates are recorded on the log, which is kept in stable storage; log has following fields: 1:Transaction name 2:Data item name, old value,new value The log has a record of and either or <T_j aborts. Write-ahead log - all updates are recorded on the log, which is kept in stable storage; log has following fields: 1:Transaction name 2:Data item name, old value,new value The log has a record of and either or <T_j aborts.

Log-Based Recovery Recovery algorithm uses two procedures: undo(T_j) - restores value of all data updated by transaction T_j to the old values (log does not contain but contains redo(T_j) Recovery algorithm uses two procedures: undo(T_j) - restores value of all data updated by transaction T_j to the old values (log does not contain but contains redo(T_j)

Checkpoints-Reduce Recovery Overhead - Output all log records currently residing in volatile storage onto stable storage. - Output all modified data residing in volatile storage to stable storage. - Output log -record onto stable storage: Recovery routine examines log to determine the most recent transaction T_ j that started executing before the most recent checkpoint took place. - Output all log records currently residing in volatile storage onto stable storage. - Output all modified data residing in volatile storage to stable storage. - Output log -record onto stable storage: Recovery routine examines log to determine the most recent transaction T_ j that started executing before the most recent checkpoint took place.

Concurrent Atomic Transactions 1. Serial Schedule -the transactions are executed sequentially in some order. E.g., Transaction_0: read(a), write(a),read(b),write(b) Transaction_1:read(a),write(a),read(b),write(b) Transaction_0 is executed first 1. Serial Schedule -the transactions are executed sequentially in some order. E.g., Transaction_0: read(a), write(a),read(b),write(b) Transaction_1:read(a),write(a),read(b),write(b) Transaction_0 is executed first

Concurrent Atomic Transactions Conflicting Operations -O_I and O_ j conflict if they access the same data item, and at least one of the operations is a write operation Conflict Serializable schedule: schedule that can be swapped into a serial schedule by a series of non-conflicting operations Conflicting Operations -O_I and O_ j conflict if they access the same data item, and at least one of the operations is a write operation Conflict Serializable schedule: schedule that can be swapped into a serial schedule by a series of non-conflicting operations

Example (continued) sequence: {read(a),write(a)}T_0, {read(a),write(a)}T_1,{read(b),write(b)}T_0,{rea d(b),write(b)}T_1 Locking Protocols: How locks rae acquired and released. Shared:T_I has obtained a lock for item Q, then it can read but not write. Exclusive: read and write Q sequence: {read(a),write(a)}T_0, {read(a),write(a)}T_1,{read(b),write(b)}T_0,{rea d(b),write(b)}T_1 Locking Protocols: How locks rae acquired and released. Shared:T_I has obtained a lock for item Q, then it can read but not write. Exclusive: read and write Q

Locking Protocol Two phase locking protocol: Growing phase: A transaction may obtain locks but not release any. Shrinking phase: A transaction ma release locks but not acquire new ones. This protocol ensures conflict serializabilty but not dead-locks Two phase locking protocol: Growing phase: A transaction may obtain locks but not release any. Shrinking phase: A transaction ma release locks but not acquire new ones. This protocol ensures conflict serializabilty but not dead-locks

Time Stamp Protocol Time-stamp ordering scheme - transaction ordering for determining serializability order. With each transaction T_j in the system, associate a unique fixed time stamp, denoted by TS(T_ j). For any new transaction T_k that comes after T_ j, TS(T_k) > TS(T_j). For each data item value, assign two timestamp values -W-timestamp(Q)- the largest timestamp of any transaction that executed Q successfully. Time-stamp ordering scheme - transaction ordering for determining serializability order. With each transaction T_j in the system, associate a unique fixed time stamp, denoted by TS(T_ j). For any new transaction T_k that comes after T_ j, TS(T_k) > TS(T_j). For each data item value, assign two timestamp values -W-timestamp(Q)- the largest timestamp of any transaction that executed Q successfully.