1. Problem description
• 1.1 Mutual Exclusion
– There are N processes and one resource.
– N processes compete for one resource.
– The resource can be accessed(used) by only
one .process at a time.
– Mutual exclusive access, deadlock-free, starvation-free
have to be guaranteed.
Distributed Algorithms
lecture 3
Resource Allocation
University of Aizu
Zixue Cheng
p1
p2
pi
……..
pn
r
1.2 Distributed resource allocation problem
1.2 Distributed resource allocation problem
• N processes and M resources.
• A subset of processes may compete for one resource.
– If M = 1 and all processes compete for the resource,
then the problem reduces to mutual exclusion problem.
• A resource can be accessed (used) by only one process at
a time.
• Every process has to acquire all resources which it
requires.
• Mutual exclusive access to a resource, deadlock-free,
starvation-free
p1
r1
p2
r2
……..
……..
pi
rj
pn
p1
p2
……..
pi
pn
r1
r2
……..
rj
rm
rm
1.3 Conventional dining philosophers problem
• There are five philosophers, a dining room with a
table, five seats around the table, and five forks on the
table.
• Every philosophers behaves like thinking, hungry (going
into the dining room, seating at a chair, picking up a fork,
picking up another fork), eating, thinking
• A fork can be used by only one philosopher at a time.
• Every philosopher has to acquire the two forks which it
requires.
• Examples of deadlock and starvation
• Mutual exclusive use a fork, deadlock-free, starvationfree
1
Deadlock, if every one picks up his right fork at the same time
Deadlock, if every one picks up his right fork at the same time
See how starvation happen
See how starvation happens
See how starvation happen
2
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
3
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
See how starvation happen
4
See how starvation happen
See how starvation happen
1.4 Distributed dining philosophers problem
• A graph (a network) with N nodes.
• A node represents a philosopher, an edge is related with a
fork.
• Any pair of neighboring nodes compete for the fork
corresponding to the edge between the pair of nodes.
• A fork can be used by only one philosopher at a time.
• Every philosopher has to acquire the all forks which it
requires.
• Mutual exclusive use of a fork, deadlock-free, starvationfree
1.5 Drinking philosophers problem
• A graph (a network) with N nodes and multiple-edges
between a pair of nodes.
• A node represents a philosopher, an edge is related with a
bottle.
• Any pair of neighboring nodes compete for a subset
of bottles corresponding to the multiple-edges between
the pair of nodes.
• A bottle can be used by only one philosopher at a time.
• Every philosopher has to acquire the all bottles which it
requires.
• Mutual exclusive use of a fork, deadlock-free, starvationfree
5
2 An algorithm for distributed dining
philosophers problem
•
2.1 Basic ideas of the algorithm
1. 2.1.1 The basic behavior of a philosopher
1. (a) A philosopher becomes hungry
2. (b) The philosopher tries to get all forks necessary for
eating by sending Request messages to its neighbors.
3. (c) The philosopher begins to eat when all the forks are
acquired.
4. (d) A philosopher sends forks to its neighbors on their
request.
2.1.2 The possible problems
(Deadlock and starvation)
1. (a) If a philosopher sends forks to their neighbors
immediately on receiving their Request message then
starvation may happen.
2. (b) If a philosopher sends forks only when it has finished
eating (used the forks), then deadlock may happen.
3. (c) When and under what condition should a philosopher
send its forks to its neighbors.
2.1.3 Solution to the problems
(Introducing a new concept “Turn”)
1.
2.
3.
4.
(a) a Turn is related with each edge (each fork)
(b) The turn is held by one endpoint (philosopher) of the edge.
(c) The philosopher held the turn has priority to use the fork
(d) A turn is sent over the corresponding edge everytime the
philosopher holding the turn finishes its eating to guarantee that
the priority to hold the fork alternates between the two
philosophers.
5. (e) A turn is different from a fork in the sense that
1. A philosopher does not need to acquire turns for all the edges
incident to it in order to eat.
2. The turns are sent to a philosopher's neighbors as soon as the
philosopher finishes its eating.
p3
p1
p2
p4
p3
p1
p2
p3
p1
p4
p2
p4
6
p3
p1
p2
p3
p1
p4
2.1.4 Detailed solution (Implementation of
above solution)
(a) The following messages are used by the algorithm
1. Request:
2. Fork(nil)
3. Fork(turn)
4. Fork(request)
(b) The following variables are used by each p hilosopher pi
1. Hungry: a boolean variable to indicate if pi wants to
eat.
2. ∀j ∈ Neighber(pi) hold_forkij:
3. ∀j ∈ Neighber(pi) hold_turnij:
4. ∀j ∈ Neighber(pi) owes_forkij:
p2
p4
2.2 Formal description of the algorithn
1. (8.11) pi sends request messages, if it becomes hungry
and the forks is not enough.
2. (8.12) Competition resolution. (how to deal with the
received request
3. (8.13) On receiving a fork
4. (8.14) On receiving a turn
2.3 Correctness of the algorithm
2.3 Correctness of the algorithm
1. Both neighbors of an edge can't hold a fork in the same
time, to guarantee mutual exclusion.
2. A fork related with an edge could be initially assigned to
any one of endpoints of the edge.
3. A turn related with an edge should be initially assigned
to an endpoint of the edge with some conditions
(described later) to guarantee deadlock-free and
starvation-free
4. New idea: directed acyclic graph
(a) Consider an edge with direction. The arrow from the endpoint
without turn to the endpoint with the turn.
Note: the directed graph is just for assign turn, but not for
describing direction of communication channel.
(b) Condition for assigning turn initially is such that there is no
cycle in the directed graph.
(c) The deadlock-free is guaranteed. Since the graph is an acyclic,
there must be at least a sink. All turns of edges of the sink
belongs the sink. So the sink will acquire all forks in finite
time. After finishing eating, the sink philosopher sends all its
turns to the corresponding neighbors, which guarantees the
graph is still acyclic. Thus deadlock never happens.
(d) The starvation-free is guaranteed.
Every philosopher has a chance to be a sink.
7
2.4 Complexities of the algorithm
1.
The message complexity of the algorithm (per every eating) is
Ο(Δ), where Δ=max∈ni N {|Neigi|}
A philosopher pi may send as many Request messages as it has
neighbors, i.e. |Neigi|. In the worst case
pi has no turn
Its neighbors are not hungry at the time receiving Request
Before pi acquires all forks, some neighbor becomes hungry
and asks to send back the corresponding fork.
pi has to return the acquired fork and ask it again.
Finally, pi acquires all turns and forks
For each edges, a Request, a fork(nil), a fork(request) a fork(turn)
messages may be used.
2.4 Complexities of the algorithm
2. The bit complexity of the algorithm is also Ο(Δ)
Consider the fact, no message includes a variable
parameter. The lengths of messages are constant.
3. The time complexity of the algorithm is Ο(n)
Consider the worst case such as a ring with only one sink.
The distance from a source to a sink may be n.
Thank you
8
© Copyright 2026 Paperzz