Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */

Slides:



Advertisements
Similar presentations
IPC (Interprocess Communication)
Advertisements

Operating Systems Part III: Process Management (Process Synchronization)
Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
1 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: mutual exclusion and synchronization Slides are mainly taken from «Operating Systems: Internals and Design Principles”, 8/E William Stallings.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles Seventh Edition By William Stallings.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A +
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
6/12/2015Page 1 Inter-Process Communication and Synchronization B. Ramamurthy.
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.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Concurrency: Mutual Exclusion, Synchronization, Deadlock, and Starvation in Representative Operating Systems.
Concurrency: Mutual Exclusion and Synchronization
02/02/2004CSCI 315 Operating Systems Design1 Interprocesses Communication Notice: The slides for this lecture have been largely based on those accompanying.
Distributed Mutual Exclusion Béat Hirsbrunner References G. Coulouris, J. Dollimore and T. Kindberg "Distributed Systems: Concepts and Design", Ed. 4,
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings 1.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago.
28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.
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.
Review Questions on Chapter IV—IPC COSC 4330/6310 Summer 2013.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
3.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Interprocess Communication Processes within a system may be.
3 Chapter 5. Theme of OS Design? Management of processes and threads Multiprogramming Multiprocessing Distributed processing.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 4.
1 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)
Synchronization Methods in Message Passing Model.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-4 Process Communication Department of Computer Science and Software.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
1 Lecture 8: Concurrency: Mutual Exclusion and Synchronization(cont.) Advanced Operating System Fall 2009.
Stacey Levine Chapter 4.1 Message Passing Communication.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Operating System Chapter 5. Concurrency: Mutual Exclusion and Synchronization Lynn Choi School of Electrical Engineering.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION.
Operating System Concepts and Techniques Lecture 14 Interprocess communication-3 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Gokul Kishan CS8 1 Inter-Process Communication (IPC)
Process Synchronization Presentation 2 Group A4: Sean Hudson, Syeda Taib, Manasi Kapadia.
Message passing model. buffer producerconsumer PRODUCER-CONSUMER PROBLEM.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization
Inter Process Communication (IPC)
Concurrency: Mutual Exclusion and Synchronization
Typically for using the shared memory the processes should:
Lecture 18: Coherence and Synchronization
Synchronization CS Spring 2002.
Presentation transcript:

Enforcing Mutual Exclusion Message Passing

Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */ flag[ 0 ] = true; turn = 1; while( flag[ 1 ] && turn == 1 ) { /* do nothing */ } /* critical section */ } } void P1() { while( true ) { flag[ 1 ] = false; /* remainder */ flag[ 1 ] = true; turn = 0; while( flag[ 0 ] && turn == 0 ) { /* do nothing */ } /* critical section */ } } 2

Peterson’s Algorithm for Processes P1 and P2 void P1() { while( true ) { flag[ 1 ] = false; /* remainder */ flag[ 1 ] = true; turn = 2; while( flag[ 2 ] && turn == 2 ) { /* do nothing */ } /* critical section */ } } void P2() { while( true ) { flag[ 2 ] = false; /* remainder */ flag[ 2 ] = true; turn = 1; while( flag[ 1 ] && turn == 1 ) { /* do nothing */ } /* critical section */ } } 3

Peterson’s Algorithm – Generalizing the “flag” variable void P1() { while( true ) { stage[ 1 ] = 0; /* remainder */ stage[ 1 ] = 1; turn = 2; while( stage[ 2 ] >= 1 && turn == 2 ) { /* do nothing */ } stage[ 1 ] = 2; /* critical section */ } } void P2() { while( true ) { stage[ 2 ] = 0; /* remainder */ stage[ 2 ] = 1; turn = 1; while( stage[ 1 ] >= 1 && turn == 1 ) { /* do nothing */ } stage[ 2 ] = 2; /* critical section */ } } 4

Peterson’s Algorithm – Generalizing the “turn” variable void P1() { me = 1; while( true ) { stage[ me ] = 0; /* remainder */ stage[ me ] = 1; polite[ 1 ] = me; while( stage[ 2 ] >= 1 && polite[ 1 ] == me ) { /* do nothing */ } stage[ me ] = 2; /* critical section */ } } void P2() { me = 2; while( true ) { stage[ me ] = 0; /* remainder */ stage[ me ] = 1; polite[ 1 ] = me; while( stage[ 1 ] >= 1 && polite[ 1 ] == me ) { /* do nothing */ } stage[ me ] = 2; /* critical section */ } } 5

Peterson’s Algorithm for Process P2 of P1, P2, and P3 void P2() { me = 2; while( true ) { stage[ me ] = 0; /* remainder */ stage[ me ] = 1; polite[ stage[ me ] ] = me; while( stage[ 1 ] >= stage[ me ] && polite[ stage[ me ] ] == me ) { /* do nothing */ } while( stage[ 3 ] >= stage[ me ] && polite[ stage[ me ] ] == me ) { /* do nothing */ } stage[ me ] = 2; polite[ stage[ me ] ] = me; while( stage[ 1 ] >= stage[ me ] && polite[ stage[ me ] ] == me ) { /* do nothing */ } while( stage[ 3 ] >= stage[ me ] && polite[ stage[ me ] ] == me ) { /* do nothing */ } stage[ me ] = 3; /* critical section */ } } 6

Message Passing Enforce mutual exclusion Exchange information send (destination, message) receive (source, message) 7

Design issues 8 Synchronization Type of Addressing Format of message Queuing discipline

Synchronization Sender and receiver each may be blocking or nonblocking Blocking send, blocking receive Both sender and receiver are blocked until message is delivered Called a rendezvous Nonblocking send, blocking receive Sender continues on Receiver is blocked until the requested message arrives Nonblocking send, nonblocking receive Neither party is required to wait 9

Addressing Direct addressing Send primitive Includes a specific identifier of the destination process Receive primitive could Know ahead of time from which process a message is expected Use source parameter to return a value when the receive operation has been performed Indirect addressing Mailboxes Messages are sent to a shared data structure Data structure consists of one or more queues Queues are called mailboxes Sender “drops off” a message at the appropriate mailbox Receiver “picks up” the message from the mailbox 10

11

Message Format 12