ALICE AND BOB DISCOVER THE PETERSON'S ALGORITHM COSC 4330/6310 Summer 2013.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
Suzuki Kasami Example. Consider 5 Sites S1 S2 S4 S3 S5 n=1 n=2 n=5 n=4 n=
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Synchronization and Deadlocks
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Operating Systems: Sync
Token-Dased DMX Algorithms n LeLann’s token ring n Suzuki-Kasami’s broadcast n Raymond’s tree.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6 (a): Synchronization.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
Concurrency: Mutual Exclusion and Synchronization - Chapter 5 (Part 2)
Chapter 2 Processes and Threads
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
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.
China’s Software Industry August 2006 Instructor: Hengming Zou, Ph.D.
Chapter 3 The Critical Section Problem
Concurrency.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
The Critical-Section Problem
CS 582 / CMPE 481 Distributed Systems
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Process Synchronization
Distributed Mutual Exclusion Béat Hirsbrunner References G. Coulouris, J. Dollimore and T. Kindberg "Distributed Systems: Concepts and Design", Ed. 4,
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Hardware solutions So far we have looked at software solutions for the critical section problem. –algorithms whose correctness does not rely on any other.
Concurrency Control Chapter 18 Section 18.5 Presented by Khadke, Suvarna CS 257 (Section II) Id
1 Lecture 9: Synchronization  concurrency examples and the need for synchronization  definition of mutual exclusion (MX)  programming solutions for.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
The Critical Section Problem
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 Distributed Process Management Chapter Distributed Global States Operating system cannot know the current state of all process in the distributed.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Solutions to Second 4330/6310 Quiz Spring First question Which of the following statements are true or false (2 points) and why? (3 points)
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
1 Shared Memory. 2 processes 3 Types of Shared Variables Read/Write Test & Set Read-Modify-Write.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization Advanced Operating System Fall 2012.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
CS3771 Today: Distributed Coordination  Previous class: Distributed File Systems Issues: Naming Strategies: Absolute Names, Mount Points (logical connection.
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
Solutions to the second midterm COSC 4330/6310 Summer 2013.
Synchronization Mutual Exclusion Solutions using shared variables + problems such as deadlocks, starvation, progressiveness, busy wait Prof. R K Joshi.
Mutual Exclusion Continued
Distributed Mutex EE324 Lecture 11.
Distributed systems II A polynomial local solution to Mutual Exclusion
The Critical-Section Problem
Critical Sections User Software Solutions Dekker’s Algorithm
Outline Distributed Mutual Exclusion Introduction Performance measures
Lecture 2 Part 2 Process Synchronization
Group Mutual Exclusion & Hadzilacos Algorithm
Thread Synchronization including Mutual Exclusion
CS 144 Advanced C++ Programming May 7 Class Meeting
Don Porter Portions courtesy Emmett Witchel
Operating Systems {week 10}
Presentation transcript:

ALICE AND BOB DISCOVER THE PETERSON'S ALGORITHM COSC 4330/6310 Summer 2013

The problem Alice and Bob share a critical section (CS) They want to ensure mutual exclusion They start by using the Reserve first and check later algorithm

How they implement it When one of them wants to enter the CS section, –It changes his/her status to "wants to enter the CS" –It repeatedly checks the status of his/her partner until this status is "is not interested" When one of them leaves the critical section, –It changes his/her status to "wants to enter the CS"

Stating point Alice is not interestedBob is not interested The critical section

Alice arrives Alice wants to use CSBob is not interested Alice is inside the CS She indicates her intention and enters the CS

Bob arrives Alice wants to use CSBob wants to use CS Alice is inside the CS Bob waits He indicates his intention but must wait

Alice leaves Alice is not interestedBob wants to use CS Bob is inside the CS Bob can now enter the CS

Alice and Bob arrive in lockstep Alice wants to use CSBob wants to use CS Deadlock Alice and Bob block each other

The tiebreaking rule When both Alice and Bob both want to enter the critical section, the last one to arrive (there is always one!) will wait –Works when one is already inside the critical section and the other arrive –Works when both arrive in lockstep

How they implement it (I) When one of them wants to enter the CS section, –He/she writes in a shared variable that he/she is the last one to request entry –He/she changes his/her status to "wants to enter the CS" –If he/she was the last one to request entry He/she repeatedly checks the status of his/her partner until this status is " is not interested "

How they implement it (II) When one of them leaves the critical section, –It changes his/her status to "is not interested"

Stating point Alice is not interestedBob does not The critical section Who arrived last?

Alice arrives Alice wants to use CSBob does not Alice is inside the CS Alice arrived last

Bob arrives Alice wants to use CSBob wants to use CS Alice is inside the CS Bob waits Bob arrived last

Alice leaves Alice is not interestedBob wants to use CS Bob is inside the CS Bob arrived last

Alice and Bob arrive in lockstep Alice wants to use CSBob wants to use CS Bob is inside the CS Alice arrived last Alice waits

How we implement it (I) Two shared variables –mustwait contains the process ID of the process that arrived last –reserved[2] an array such that reserved[i] == 1 if process i wants to enter the critical section reserved[i] == 0 otherwise

How we implement it (II) The entry rule is other = 1 - pid ; mustwait = pid;//last arrived while ((reserved[other] == 1) && (must wait == pid)) ; Busy wait