Synchronization with Eventcounts and Sequencers

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
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.
COP 4600 Operating Systems Fall 2010 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 3:30-4:30 PM.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Classic Synchronization Problems
Chapter 6 Concurrency: Deadlock and Starvation
Classical Problems of Concurrency
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
CPSC 4650 Operating Systems Chapter 6 Deadlock and Starvation
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor.
1 Concurrency: Deadlock and Starvation Chapter 6.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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.
Critical Problem Revisit. Critical Sections Mutual exclusion Only one process can be in the critical section at a time Without mutual exclusion, results.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Process Synchronization.  Whenever processes share things, there is a chance for screwing up things  For example ◦ Two processes sharing one printer.
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
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, Lecture 11: Synchronization (Chapter 6, cont)
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
Deadlock Operating Systems: Internals and Design Principles.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Readers/Writers Problem  Multiple processes wanting to read an item, and one or more needing to write (Think of airline reservations…)  Rather than enforce.
Informationsteknologi Monday, October 1, 2007Computer Systems/Operating Systems - Class 111 Today’s class Deadlock.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Deadlock and Starvation
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
“Language Mechanism for Synchronization”
Process Synchronization
Concurrent Processes.
Deadlock and Starvation
Chapter 5: Process Synchronization (Con’t)
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Chapter 7: Synchronization Examples
Concurrency: Mutual Exclusion and Process Synchronization
Chapter 7: Synchronization Examples
CSE 542: Operating Systems
Presentation transcript:

Synchronization with Eventcounts and Sequencers David P. Reed Rajendra K. Kanodia

Introduction What is it used for? Synchronizing the use of shared resources How is it different from semaphores and monitors? Mutual exclusion

EventCounts What is an eventcount? Tracks number of events Non-decreasing integer variable

EventCount operations advance(E) read(E) await(E, v)

advance( E ) Signals occurrence of an event Update eventcount value

read( E ) Returns value of eventcount May or may not count events in progress

await( E, v ) Similar to read( E ) Waits for value v to be reached May not return immediately once the vth advance is executed

Producer/Consumer Example N-cell ring buffer buffer[0:N –1] Eventcounts IN and OUT produce() to generate items

Single producer code Procedure producer() begin integer i; for i:= 1 to infinity do begin await( OUT, i – N); buffer[i mod N] := produce( ); advance( IN ); end

Single consumer code Procedure consumer() begin integer i; Procedure producer() begin integer i; for i:= 1 to infinity do begin await( OUT, i – N); buffer[i mod N] := produce( ); advance( IN ); end Procedure consumer() begin integer i; for i := 1 to infinity begin await( IN, i ); consume( buffer[i mod N]); advance( OUT ); end

Possible Situations Fast Producer Fast Consumer Producer will wait until item it is trying to overwrite is consumed. Fast Consumer Consumer will wait until the producer has added the value.

EventCount observations How is this solution different than semaphores? Relative ordering rather than mutual exclusion. Producer & consumer can be concurrent. Never does a process have to wait due to synchronization.

Sequencers Used when synchronization requires arbitration Used to order the events Useful with Eventcounts but not on its own Non-decreasing integer value

Sequencer operations ticket(S) Value returned is the process’s ordering. Two calls to ticket( S ) will always return different values.

Producer/Consumer Example Same as with Eventcounts but multiple producers now Sequencer T Use ticket(T) to synchronize with other producers

buffer[t+1mod N] := produce( ); advance( IN ); end Procedure producer() begin integer i; for i:= 1 to infinity do begin await( OUT, i – N); buffer[i mod N] := produce( ); advance( IN ); end Procedure producer() begin integer t; do forever begin t := ticket(T); await( IN, t); await( OUT, t – N + 1 ) buffer[t+1mod N] := produce( ); advance( IN ); end

Relation to semaphores Lower level than Semaphores Semaphores can be built from Eventcounts and Sequencers

Semaphore Example Semaphore S EventCount is S.E Sequencer is S.T Initial value of S is S.I

Semaphore Wait Procedure P(S) begin integer t; t := ticket( S.T ); await( S.E, t – S.I ); end

Semaphore Signal Procedure V( S ) begin advance( S.E ) end

Deadlock Free Simultaneous P 2 Semaphores R and S Global semaphore G to synchronize part of operation

Procedure Pboth( R, S ) begin integer g, r, s; g := ticket( G.T ); await( G.E, g ); r := ticket( R.T ); s := ticket( S.T ); advance( G.E ); await( R.E, r – R.I ); await( S.E, s – S.I ); end

Observations G is used for obtaining tickets await operation could be deferred Useful in solving the Dining Philosophers Problem

Observations Process destroyed while holding 1 ticket Keep the window during which a process has an unredeemed a ticket short Don’t allow destroying the process during the window

Flow of information operations are: Observer or Signaler unlike the semaphore wait Easily adapted to permissions Observer permission(advance). signaler permission(read,await). Useful in secure systems

Secure Readers - Writers Shared database Readers have observer permission Writers have observer and signaler permission Writer priority S and C are eventcounts T is a sequencer

Reader code Procedure reader() begin integer w; abort: w := read(S); await(C, w); “read DB” if read(S) ≠ w then goto abort; end

Writer code Procedure writer() begin integer t; advance( S ); t := ticket( T ); await( C, t ); advance( C ); end

Conclusion new mechanism for synchronization. not based on mutual exclusion. Provides an interface between processes. Information flow paths are clear. Effective in secure systems. Unnecessary serialization avoided.