1 / 12

2.4 Classic IPC Problems

2.4 Classic IPC Problems. Dining philosophers Readers and writers Sleeping barber. 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. Dining philosphers.

abla
Télécharger la présentation

2.4 Classic IPC Problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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. Dining philosphers

  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(); for ( ; ; ) { take_fork( i ); if (try_take_fork( (i+1)%N )) { put_fork( i ); break; } } eat(); put_fork( i ); put_fork( (i+1)%N ); } } How does this lead to starvation? problem

  7. Dining philosopherssolution

  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 barbersolution

More Related