Peculiarity of Peterson’s Solution to Process Synchronization

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
For(int i = 1; i
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
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 ©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.
Operating System Concepts and Techniques Lecture 12 Interprocess communication-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Secure Operating Systems Lesson 5: Shared Objects.
SOLUTIONS FOR THE SECOND 4330 QUIZ Jehan-Francois Paris Summer 2014.
1 Operating Systems, 112 Practical Session 5, Synchronization 1.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
Interprocess Communication
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Introduction to Synchronization CS-3013 C-term Introduction to Synchronization CS-3013 Operating Systems (Slides include materials from Operating.
Introduction to Synchronization CS-3013 A-term Introduction to Synchronization CS-3013 Operating Systems (Slides include materials from Modern Operating.
Introduction to Synchronization CS-3013 A-term Introduction to Synchronization CS-3013, Operating Systems A-term 2009 (Slides include materials from.
1 Outline Processes Threads Inter-process communication (IPC) Classical IPC problems Scheduling.
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Concurrency 1 CS502 Spring 2006 Thought experiment static int y = 0; int main(int argc, char **argv) { extern int y; y = y + 1; return 0; }
Concurrency & Synchronization CS-502 Fall Concurrency (continued) and Synchronization CS-502 Operating Systems Fall 2007 (Slides include materials.
ELN5622 Embedded Systems Class 8 Spring, 2003 Aaron Itskovich
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion.
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.
TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION2 OPERATING SYSTEMS.
Equations Reducible to Quadratic
ConcurrencyCS-502 Fall Concurrency CS-502 Operating Systems Fall 2007 (Slides include materials from Operating System Concepts, 7 th ed., by Silbershatz,
Solutions to Second 4330/6310 Quiz Spring First question Which of the following statements are true or false (2 points) and why? (3 points)
More review questions for the second midterm COSC 4330/6310.
CY2003 Computer Systems Lecture 04 Interprocess Communication.
Module 2.1: Process Synchronization
Thread Implementations; MUTEX Reference on thread implementation –text: Tanenbaum ch. 2.2 Reference on mutual exclusion (MUTEX) –text: Tanenbaum ch
Chapter 2 Chapter 2: Processes & Threads Part 2 Interprocess Communication (IPC) & Synchronization.
Fundamentals of Parallel Computer Architecture - Chapter 71 Chapter 7 Introduction to Shared Memory Multiprocessors Yan Solihin Copyright.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
A: A: double “4” A: “34” 4.
IPC and IPS Problems Jehan-François Pâris
Chapter IX Review Questions and Problems Jehan-François Pâris
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
CS 3013 & CS 502 Summer 2006 Concurrency & Processes1 CS3013 & CS502 Operating Systems.
Solutions to the second midterm COSC 4330/6310 Summer 2013.
Practical Session 5 Synchronization
Graphing a System of Inequalities
Factors, multiple, primes: Factors from prime factors
Lecture 12: Peterson’s Solution and Hardware Support
Lecture 13: Producer-Consumer and Semaphores
Review Operation Bingo
Practical Session 5 Synchronization
Factors, multiple, primes: Prime factors
Practical Session 5 Synchronization
Practical Session 5, Synchronization
Chapter 6: Process Synchronization
Introduction to Synchronization
Introduction to Synchronization
Problems discussed in the review session for the second midterm
Lecture 12: Peterson’s Solution and Hardware Support
Lecture 13: Producer-Consumer and Semaphores
Factors, multiple, primes: Multiples
Concurrency & Processes
Standard Form: Multiplying powers of 10
Standard form: In standard form?
Process Synchronization
Coordinates: Naming 2D coordinates – quadrant 1
Operating Systems {week 10}
Exercise (6).
Presentation transcript:

Peculiarity of Peterson’s Solution to Process Synchronization

void enter_region(int process) { int other = 1 – process; turn Initial State interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } FALSE while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } TRUE TRUE while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } TRUE TRUE So, wait…  while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1

void enter_region(int process) { int other = 1 – process; Process 1 turn 1 But process 1 was supposed to enter its critical region…  interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} }  void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1