Presentation is loading. Please wait.

Presentation is loading. Please wait.

2.4 Classic IPC Problems Dining philosophers Readers and writers

Similar presentations


Presentation on theme: "2.4 Classic IPC Problems Dining philosophers Readers and writers"— Presentation transcript:

1 2.4 Classic IPC Problems Dining philosophers Readers and writers
Sleeping barber

2 Dining philosphers Philosphers eat and think.
To eat, they must first acquire a left fork and then a right fork (or vice versa). Then they eat. Then they put down the forks. Then they think. Go to 1.

3 Dining philosphers Problems: Deadlock Starvation

4 Dining philosophers (non solution)

5 Dining philosophers (poor solution)
down(mutex); up(mutex); Too much blocking – not very parallel but it works.

6 Dining philosophers (non solution)
void philosopher ( int i ) { for ( ; ; ) { think(); take_fork( i ); if (try_take_fork( (i+1)%N )) { put_fork( i ); break; } eat(); put_fork( (i+1)%N ); How does this lead to starvation? problem

7 Dining philosophers solution

8 Readers and writers Multiple readers can concurrently read from the data base. But when updating the db, there can only be one writer (i.e., no other writers and no readers either)

9 Readers and writers Suffers from starvation (as long as there are readers, a writer is starved).

10 Sleeping barber

11 Sleeping barber problem
One barber, one barber chair, and N seats for waiting. No customers so barber sleeps. Customer comes in & wakes up barber. More customers come in. If there is an empty seat, they take a seat. Otherwise, they leave.

12 Sleeping barber solution


Download ppt "2.4 Classic IPC Problems Dining philosophers Readers and writers"

Similar presentations


Ads by Google