ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Operating Systems Mehdi Naghavi Winter 1385.
Chapter 6: Process Synchronization
Stuff  Exam timetable now available  Class back in CS auditorium as of Wed, June 4 th  Assignment 2, Question 4 clarification.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
COSC 3407: Operating Systems Lecture 8: Semaphores, Monitors and Condition Variables.
Classic Synchronization Problems
DPNM Lab. Dept. of CSE, POSTECH
Classical Problems of Concurrency
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Concurrency: Deadlock and Starvation Chapter 6. Revision Describe three necessary conditions for deadlock Which condition is the result of the three necessary.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Process Synchronization
IPC and Classical Synchronization Problems
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
6: Process Synchonization II 1 PROCESS SYNCHRONIZATION II THE BOUNDED BUFFER ( PRODUCER / CONSUMER ) PROBLEM: This is the same producer / consumer problem.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
CS3530 OPERATING SYSTEMS Summer 2014 Synchronization Chapter 6.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 23 Classic Synchronization.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
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.
Synchronization II: CPE Operating Systems
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 6: Process Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
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)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 6: Process Synchronization.
Semaphores Ref: William Stallings G.Anuradha. Principle of a Semaphore Two or more processes can cooperate by means of simple signals, such that a process.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
Producer-Consumer Problem David Monismith cs550 Operating Systems.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Operating System Concepts and Techniques Lecture 16 Deadlock and starvation-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
Classic problems of Synchronization : Producers/Consumers problem: The producers/ consumers problem may be stated as follows: Given a set of cooperating.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Synchronization Background The Critical-Section Problem Peterson’s.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Classical IPC Problems
Dining Philosophers Five philosophers sit around a table
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Classical Synchronization Problems
2.4 Classic IPC Problems Dining philosophers Readers and writers
Chapter 5: Process Synchronization (Con’t)
Happy Children’s Day.
Lecture 25 Syed Mansoor Sarwar
Process Synchronization
Process Synchronization
DPNM Lab. Dept. of CSE, POSTECH
Chapter 7: Synchronization Examples
Chapter 7: Synchronization Examples
Presentation transcript:

ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH

ITEC502 컴퓨터 시스템 및 실습 2 Contents 1.Classical IPC Problems  Bounded buffer problems (Producer-Consumer)  Readers and Writers problems  Dining-philosophers problems  Sleeping barber problems

ITEC502 컴퓨터 시스템 및 실습 3 Bounded-Buffer Problem (1)  More than two producers – produce one item, store it in the buffer, and continue  More than two consumers – consume a item from buffer, and continue  The buffer contains at most N items  Solution with semaphore –Semaphore mutex initialized to the value 1 –Semaphore full initialized to the value 0 –Semaphore empty initialized to the value N

ITEC502 컴퓨터 시스템 및 실습 4 Bounded-Buffer Problem (2) The bounded buffer problem using semaphores

ITEC502 컴퓨터 시스템 및 실습 5 Readers-Writers Problem (1)  A data set is shared among a number of concurrent processes –Readers: only read the data set; they do not perform any updates –Writers: can both read and write  Problem: allow multiple readers to read at the same time Only one single writer can access the shared data at the same time  Shared Data –Data set –Semaphore mutex initialized to 1 –Semaphore db initialized to 1 –Integer rc //readcount initialized to 0

ITEC502 컴퓨터 시스템 및 실습 6 Readers-Writers Problem (2)  Starvation is the problem … –The writer may starve –No readers will be kept waiting unless a writer has already obtained permission to use the shared object  Another variation of Readers-Writers Problem –Once a writer is ready, that the writer performs its write as soon as possible –If a writer is waiting to access the object, no new readers may start reading  In this case, the readers may starve  What is the starvation free solution for Readers-Writers Problem?

ITEC502 컴퓨터 시스템 및 실습 7 Readers-Writers Problem (3) A solution to the readers and writers problem

ITEC502 컴퓨터 시스템 및 실습 8 Dining-Philosophers Problem (1)  Five philosophers who spend their lives thinking and eating  They share a circular table surrounded by five chairs  In the center of the table is a bowl of rice  File single chopsticks on the table  When a philosophers think, she does not interact with neighbors  From time to time, she gets hungry and try to pick up the two chopsticks that are closest to her  She picks up only one chopsticks at a time  She cannot pick up the chopstick that is already in the hand of a neighbor  When she gets two chopsticks, she eats without releasing them  When she finished eating, she put down both chopsticks and think again  How to implement this with concurrent processors in a deadlock-free and starvation-free manner?

ITEC502 컴퓨터 시스템 및 실습 9 Dining-Philosophers Problem (2)  It is a large class of concurrency-control problems  It is a simple representation of the need to allocate several resources among several processes in a deadlock- free and starvation-free manner  Simple Solution …  Shared data –Bowl of rice (data set) –Semaphore s [5] initialized to 1

ITEC502 컴퓨터 시스템 및 실습 10 Dining-Philosophers Problem (3)  This solution guarantees that –No two neighbors are eating simultaneously  However, this solution creates deadlock –Suppose all five philosophers become hungry simultaneously and each grabs her left chopsticks –All chopsticks are taken –When each philosophers tries to grab her right chopstick, she delays forever  Possible deadlock free solutions –Allow at most four philosophers to be sitting together –Allow a philosopher to pick up her chopsticks only if both chopsticks are available –Use an asymmetric solution; an odd one picks up left chopstick first, an even one picks up right chopstick first

ITEC502 컴퓨터 시스템 및 실습 11 Dining-Philosophers Problem (4) A nonsolution to the dining philosophers problem

ITEC502 컴퓨터 시스템 및 실습 12 Dining-Philosophers Problem (5) Solution to dining philosophers problem (part 1)

ITEC502 컴퓨터 시스템 및 실습 13 Dining-Philosophers Problem (6) Solution to dining philosophers problem (part 2)

ITEC502 컴퓨터 시스템 및 실습 14 Sleeping-Barber Problem (1)

ITEC502 컴퓨터 시스템 및 실습 15 Sleeping-Barber Problem (2) Solution to sleeping barber problem

ITEC502 컴퓨터 시스템 및 실습 16 Summary  Semaphore can be used to solve various synchronization problems –The bounded-buffer, The readers-writers, The dining-philosophers, The sleeping-barber problems –Those are examples of a large class of concurrency-control problems –The solution should be deadlock-free and starvation-free