Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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

3 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

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

5 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

6 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?

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

8 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?

9 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

10 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

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

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

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

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

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

16 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


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

Similar presentations


Ads by Google