9
Dining- Philosophers Problem

DPP

Embed Size (px)

DESCRIPTION

Presentation

Citation preview

Page 1: DPP

Dining-Philosophers Problem

Page 2: DPP

Dining-Philosophers Problem The philosophers share a circular table

surrounded by five chairs, each belonging to one philosopher

In the center of table is a bowl of rice, and the table is laid with 5 single chopsticks

From time to time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest to her

When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks

When she is finished eating, she puts down both her chopsticks and starts thinking

Page 3: DPP

Dining-Philosophers Problem

Page 4: DPP

Dining-Philosophers Problem

Page 5: DPP

Dining-Philosophers Problem

Methods to avoid deadlock: Allow at most four philosophers to

be sitting simultaneously Allow a philosopher to pick up her

chopsticks only if both chopsticks are available (pick them up is a critical section)

Page 6: DPP

Problems with Semaphores

signal (mutex) //violate mutual exclusive critical sectionwait (mutex)

wait (mutex) //deadlock occurs critical sectionwait (mutex)

Omitting of wait (mutex) or signal (mutex) (or both)

Page 7: DPP

Solution to Dining Philosophers

Page 8: DPP

Solution to Dining Philosophers

Page 9: DPP

Solution to Dining Philosophers

Each philosopher I invokes the operations pickup() and putdown() in the following sequence:

dp.pickup(i) EATdp.putdown(i)