OS Winter’03 Concurrency. OS Winter’03 Bakery algorithm of Lamport  Critical section algorithm for any n>1  Each time a process is requesting an entry.

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

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
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
Synchronization Principles Gordon College Stephen Brinton.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
OS Spring’04 Concurrency 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.
02/23/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.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
OS Fall’02 Concurrency Operating Systems Fall 2002.
Synchronization Solutions
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.
Concurrency, Mutual Exclusion and Synchronization.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
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.
1 Concurrency: Mutual Exclusion and Synchronization Module 2.2.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
3.1. Concurrency, Critical Sections, 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 ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
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.
Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
Bakery Algorithm - Proof
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
CS703 – Advanced Operating Systems
Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Chapter 5: Process Synchronization
Chapter 6-7: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Synchronization Tools
Topic 6 (Textbook - Chapter 5) Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Module 7a: Classic Synchronization
Synchronization and Semaphores
Lecture 2 Part 2 Process Synchronization
Critical section problem
Chapter 6: Process Synchronization
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
Process/Thread Synchronization (Part 2)
CSE 542: Operating Systems
Presentation transcript:

OS Winter’03 Concurrency

OS Winter’03 Bakery algorithm of Lamport  Critical section algorithm for any n>1  Each time a process is requesting an entry to CS, assign it a ticket which is Unique and monotonically increasing  Let the process into CS in the order of their numbers

OS Winter’03 Choosing a ticket Does not guarantee uniqueness! Use process Ids: Process need to know that somebody perhaps chose a smaller number:

OS Winter’03 Bakery algorithm for n processes

OS Winter’03 Correctness Lemma: Mutual exclusion is immediate from this lemma It is easy to show that Progress and Fairness hold as well (recitation)

OS Winter’03 Hardware primitives  Elementary building blocks capable of performing certain steps atomically Should be universal to allow for solving versatile synchronization problems  Numerous such primitives were identified: Test-and-set Fetch-and-add Compare-and-swap

OS Winter’03 Test-and-Set (TS) boolean test-and-set(boolean &lock) { temp=lock; lock=TRUE; return temp; } reset(boolean &lock) { lock=FALSE; }

OS Winter’03 Critical section using TS Shared boolean lock, initially FALSE do { while(test-and-set(&lock)); critical section; reset(&lock); reminder section; } while(1); Check yourself! Is mutual exclusion satisfied? Is progress satisfied? Is fairness satisfied?

OS Winter’03 Discussion  Satisfies Mutual Exclusion and Progress  Does not satisfies Fairness  Provides exclusion among unbounded number of processes Process IDs and number are unknown  Busy waiting Burning CPU cycles while being blocked

OS Winter’03 Fetch-and-Add (FAA) s: shared, a: local int FAA(int &s, int a) { temp=s; s=s+a; return temp; } FAA can be used as a ticket machine

OS Winter’03 Critical section using FAA Shared: int s, turn; Initially: s = 0; turn=0; Process P i code: Entry: me = FAA(s,1); while(turn < me); // busy wait for my turn Critical section Exit: FAA(turn,1); Check yourself! Is mutual exclusion satisfied? Is progress satisfied? Is fairness satisfied?

OS Winter’03 Discussion  Satisfies all three properties  Supports unbounded number of processes  Unbounded counter  Busy waiting

OS Winter’03 Problems with studied synchronization methods  Critical section framework is inconvenient for programming  Performance penalty Busy waiting Too coarse synchronization  Using hardware primitives directly results in non-portable code

OS Winter’03 Higher Level Abstractions  Higher level software abstractions are represented by Semaphores Monitors

OS Winter’03 Semaphores  Invented by Edsger Dijkstra in 1968  Interface consists of two primitives: P() and V()

OS Winter’03 Notes on the Language  Dutch: P: Proberen, V: Verhogen  Hebrew: P: פחות, V: ועוד  English: P(): wait(), V(): signal()

OS Winter’03 Semaphores: initial value  Initial value of a semaphore indicates how many identical instances of the critical resource exist  A semaphore initialized to 1 is called a mutex (mutual exclusion)

OS Winter’03 Programming with semaphores  Semaphores is a powerful programming abstraction  Define a semaphore for each critical resource E.g., one for each linked list Granularity?  Concurrent processes access appropriate semaphores when synchronization is needed

OS Winter’03 Some examples … V(synch); … P(synch); …

OS Winter’03 Some examples Do { P(mutex); critical section V(mutex); Remainder section; While(1);

OS Winter’03 Implementing semaphores  Semaphores can be implemented efficiently by the system P() is explicitly telling the system: “ Hey, I cannot proceed, you can preempt me ” V() instructs the system to wake up a waiting process

OS Winter’03 Implementing Semaphores type semaphore = record count: integer; queue: list of process end; var S: semaphore; S.count must be initialized to a nonnegative value (depending on application)

OS Winter’03 Implementing Semaphores P(S): S.count--; if (S.count<0) { add this process to S.queue block this process; } V(S): S.count++; if (S.count <= 0) { remove a process P from S.queue place this process P on ready queue }

OS Winter’03 We ’ re still cheating …  P() and V() must be executed atomically  In uniprocessor system may disable interrupts  In multi-processor system, use hardware synchronization primitives TS, FAA, etc …  Involves a some limited amount of busy waiting

OS Winter’03 Monitors monitor monitor-name { shared variable declarations procedure P1(…) { … } … procedure Pn() { … }  Only a single process at a time can be active within the monitor => other processes calling Pi() are queued  Conditional variables for finer grained synchronization x.wait() suspend the execution until another process calls x.signal()