Title: Generalized dining philosophers
1Generalized dining philosophers
- Catuscia Palamidessi, INRIA
- in collaboration with
- Mihaela Oltea Herescu, IBM
- Michael Pilquist, PSU
2Plan of the talk
- What we mean by Generalized dining philosophers
- two levels of generalization
- Motivations
- The classic deadlock-free solution by Lehmann and
Rabin - Problems with the classic solution
- fairness assumption adversaries
- restrictions on the connection structure
- A solution for the first generalization (w/o the
fairness assumption) - A solution for the second generalization (w/
fairness assumption).
3Dining Philosophers classic case
- Each philosopher needs exactly two forks
- Each fork is shared by exactly two philosophers
4Dining Phils generalization 1
- Each phil still needs two forks, but
- Each fork can now be shared by more than two
philosophers
- We will consider arbitrary graphs
- arcs ? philosophers
- vertices ? forks
- Of course, the problem is interesting when there
is at least one cycle
5Dining Phils generalization 2
- Each phil needs an arbitrary number of forks
- Each fork can be shared by an arbitrary number
of phils
- We will consider arbitrary bipartite graphs
- vertices 1 ? philosophers
- vertices 2 ? forks
- Of course, the problem is interesting when there
is at least one cycle
6Intended properties of soln
- Deadlock freedom (aka progress) if there is a
hungry philosopher, a philosopher will eventually
eat - Starvation freedom every hungry philosopher will
eventually eat (but we wont consider this
property here) - Robustness wrt a large class of adversaries
Adversaries decide who does the next move
(schedulers) - Fully distributed no centralized control or
memory - Symmetric
- All philosophers run the same code and are in the
same initial state - The same holds for the forks
7Motivations
- To model real systems, in which the relation
between resources and users may be more
complicate than a ring - Our main motivation Distributed and modular
implementation of the mixed choice mechanism of
the p-calculus (and CCS, CSP etc.) - mixed choice both input and output guards are
present - (out(a).P1 in(b).P2) (in(a).Q1
out(b).Q2) - ? P1 Q1
- ? P2 Q2
- Our approach use the asynchronous p-calculus (no
choice, no output guards) as an intermediate
language. The asynchronous p-calculus can be
implemented in a distributed, modular way.
8Encoding p into ppa
- Every mixed choice is translated into a parallel
comp. of processes corresponding to the branches,
plus a lock f - The input processes compete for acquiring both
its own lock and the lock of the partner - The input process which succeeds first,
establishes the communication. The other
alternatives are discarded
f
Pi
P
R
f
Ri
Qi
Ri
Q
S
f
f
Si
The problem is reduced to a generalized DP
problem where each fork (lock) can be adjacent to
more than two philosophers (generalization 1).
We are interested in progress, i.e. deadlock
freedom.
9Encoding p into asynchonous p
- The requirements on the encoding imply symmetry
and full distribution - There are many solution to the DP problem, but
only randomized solutions can be symmetric and
fully distributed. - Lehmann and Rabin 81 - They also provided a
randomized algorithm (for the classic case) - Hence we have actually considered a
probabilistic extension of the asynchronous p for
the implementation. - Note that the DP problem can be solved in p in a
fully distributed, symmetric way - Francez and Rodeh 80 they actually use CSP
- Hence the need for randomization is not a
characteristic of our approach it would arise in
any encoding of p into an asynchronous language.
10The algorithm of Lehmann and Rabin
- Think
- choose first_fork in left,right commit
- if taken(first_fork) then goto 3
- take(first_fork)
- if taken(first_fork) then goto 2
- take(second_fork)
- eat
- release(second_fork)
- release(first_fork)
- goto 1
11Problems
- Wrt to our encoding goal, the algorithm of
Lehmann and Rabin has two problems - It only works for certain kinds of graphs
- It works only for fair schedulers
- Problem 2 however can be solved by replacing the
busy waiting in step 3 with suspension. - Duflot, Friburg, Picaronny 2002 see also
Herescus PhD thesis
12The algorithm of Lehmann and RabinModified so to
avoid the need for fairness
- Think
- choose first_fork in left,right commit
- if taken(first_fork) then wait
- take(first_fork)
- if taken(first_fork) then goto 2
- take(second_fork)
- eat
- release(second_fork)
- release(first_fork)
- goto 1
13Restriction on the graph
- Theorem The algorithm of Lehmann and Rabin is
deadlock-free if and only if all cycles are
pairwise disconnected - There are essentially three ways in which two
cycles can be connected
14Proof of the theorem
- If part) Each cycle can be considered
separately. On each of them the classic
algorithm is deadlock-free. Some additional care
must be taken for the arcs that are not part of
the cycle. - Only if part) By analysis of the three possible
cases. Actually they are all similar. We
illustrate the first case
committed
taken
15Proof of the theorem
- The initial situation has probability p gt 0
- The scheduler forces the processes to loop
- Hence the system has a deadlock (livelock) with
probability p - Note that this scheduler is not fair. However we
can define even a fair scheduler which induces an
infinite loop with probability gt 0. The idea is
to have a scheduler that gives up after n
attempts when the process keep choosing the
wrong fork, but that increases (by f) its
stubborness at every round. - With a suitable choice of n and f we have that
the probability of a loop is p/4
16Solution for the Generalization 1
- As we have seen, the algorithm of Lehmann and
Rabin does not work on general graphs - However, it is easy to modify the algorithm so
that it works in general - The idea is to reduce the problem to the pairwise
disconnetted cycles case - Each fork is initially associated with one
token. Each phil needs to acquire a token in
order to participate to the competition. After
this initial phase, the algorithm is the same as
the Lemahn Rabins - Theorem The competing phils determine a
graph in which all cycles are pairwise
disconnected - Proof By case analysis. To have a situation
with two connected cycles we would need a node
with two tokens.