Asynchronous Group Mutual Exclusion in Ring Networks
(Extended Abstract)
Kuen-Pin Wu
Department of Electrical Engineering
National Taiwan University
Taipei, Taiwan
kpw@orchid.ee.ntu.edu.tw
Yuh-Jzer Joung
Department of Information Management
National Taiwan University
Taipei, Taiwan
joung@ccms.ntu.edu.tw
Abstract
The design issues for group mutual exclusion have been modeled by Joung as the Congenial Talking
Philoso-phers, and solutions for shared-memory models and
com-plete message-passing networks have been proposed [2, 3]. These solutions, however, cannot be straightforwardly and efficiently converted to ring networks where each philoso-pher can only communicate directly with its two neighbor-ing philosophers. As rings are also a popular network topology, in this paper we focus the Congenial Talking Philosophers on ring networks and present an efficient and highly concurrent distributed algorithm for the problem.
1
Introduction
The design issues for mutual exclusion between groups of processes have recently been modeled by Joung [2] as the Congenial Talking Philosophers, which concerns a set of
N
philosophersp
1;p
2;::: ;p
N
which spend their time thinking alone and talking in a forum. Initially, all philosophers are thinking. From time to time, when a philosopher is tired of thinking, it wishes to attend a forum of its choice. Given that there is only one meeting room, a philosopher attempting to enter the meeting room to attend a forum can succeed only if the meeting room is empty (and in this case the philosopher starts the forum), or some philosopher interested in the same forum is already in the meeting room (and in this case the philosopher joins this ongoing forum). We assume that when a philosopher has attended a forum, it spends an unpredictable but finite amount of time in the forum. After a philosopher leaves a forum (and exits the meeting room)1, it returns to thinking. The problem is to design an algorithm for the philosophers satisfying the following requirements:mutual exclusion: if some philosopher is in a forum,
then no other philosopher can be in a different forum
This research was supported in part by the National Science Council, Taipei, Taiwan, under Grants NSC 85-2213-E-002-059 and NSC 86-2213-E-002-053.
1Throughout the paper, “in a forum” is synonymously with “in the
meeting room.” So, “to attend/leave a forum” is synonymously with “to enter/exit the meeting room.”
simultaneously.
bounded delay: a philosopher attempting to attend a
fo-rum will eventually succeed.
concurrent entering: if some philosophers are interested
in a forum and no philosopher is interested in a different forum, then the philosophers can attend the forum concurrently.
Solutions for the Congenial Talking Philosophers prob-lem for shared-memory models and complete message-passing networks have been proposed [2, 3]. These solu-tions, however, cannot be straightforwardly and efficiently converted to ring networks where each philosopher can only communicate directly with its two neighboring philoso-phers. As rings are also a popular network topology, in this paper we focus the problem on ring networks where the
N
philosophersp
0;p
1;::: ;p
N
,1are connected via a ring net-work so that each philosopherp
i
can only send messages directly to its immediate successorp
i
+1. (Unless stated, otherwise, additions and subtractions on indices of philoso-phers are to be interpreted moduloN
.) We shall assume that philosophers are distinguished by their unique IDs, and that every message will eventually be delivered to its destina-tion. However, we do not require messages to be delivered in the order sent.As we shall see, some solutions for the Congenial Talk-ing Philosophers problem may be easy to design. However, their “performance” in practical applications may be unsat-isfactory. So Joung has also proposed four measurements to evaluate the algorithms. We shall briefly discuss these mea-surements in the following section. For more details, please refer to [2, 3]. Section 3 presents a straightforward solution to the Congenial Talking Philosophers problem. The solu-tion easily satisfies the three problem requirements, and has complexity measures that “appear” to be acceptable. How-ever, when putting the algorithm in simulation, its weak-ness becomes evident: the performance is only slightly bet-ter than imposing strict mutual exclusion on every entry to the meeting room. A more concurrent solution is therefore presented in Section 4. Section 5 concludes.
2
Complexity Measures
Solutions for the Congenial Talking Philosophers prob-lem can be evaluated from the following four perspectives:
messages, time, context-switch, and degree of concurrency.
Message complexity is concerned with how many mes-sages the system generates per entry to the critical section— the meeting room.
For time, one is concerned with how long a philosopher
p
i
should wait before it enters the critical section from the time it has made a request (by sending out messages to other philosophers). More formally, define a passage throughX byp
i
to be an interval[
t
1;t
2]
, wheret
1 is the timep
i
en-ters the meeting room to attendX, andt
2is the time it exits the meeting room. The attribute of the passage is denoted byhp
i
;
Xi. When no confusion is possible, intervals and at-tributes are used interchangeably to represent passages. We often say that the passage is initiated att
1, and is completed att
2. The passage is ongoing at any time in betweent
1andt
2.Let
T
be the set of passages that may be initiated after a philosopherp
i
has made a request for a forum, and that must be completed beforep
i
can enter the meeting room. The time complexity is measured by(
T
)
, where(
T
)
is the size of a minimal setR
T
such that for every passage 2T
, every time instance inis contained in some2R
. The context-switch complexity is measured by the max-imum number of rounds of passages that may be initiated after a philosopher has made a request for X, but before a round ofX is initiated in whichp
i
can make a passage through X. A round of passages through Y (or simply a round of Y) is a maximal set of consecutive passages through forumY.The (maximum) degree of concurrency is defined by the maximum number of entries to the meeting room that can still be made while some philosopher is in the meeting room and another philosopher is waiting for a different forum.
Note that the above complexity measures all concern worst-case scenarios. Due to the dynamic nature of the problem, an average-case analysis is extremely compli-cated and so simulation studies [5] are also suggested by Joung [3].
3
A Straightforward Solution
We first present a straightforward solution to the Con-genial Talking Philosophers problem over a ring network. In the algorithm, which we shall refer to as CTP-Ring1 (where CTP stands for Congenial Talking Philosophers), each philosopher is in one of the following three states:
thinking
, meaning that it is not interested in any forum;waiting
, meaning that it is waiting for a forum; andtalking
, meaning that it is in a forum. Moreover, each philosopher maintains a variableSN
recording the maximum sequence number seen by the philosopher. The variable will be main-tained similar to Lamport’s logical clock [4]. That is, each philosopher initializes itsSN
to 0 and, whenever it learns of a sequence number larger than its ownSN
, it advances itsSN
to that number. Furthermore, a philosopher increments itsSN
by 1 when it wishes to attend a forum.Initially, every philosopher is in state
thinking
. When a philosopherp
i
wishes to attend a forumX, it enters statewaiting
, increments itsSN
by 1, and sends a request mes-sageReq
(
hi;
sn
i;
X)
to its successorp
i
+1, wheresn
is thenew value of
p
i
’sSN
. Philosopherp
i
remains in statewaiting
until its requestReq
(
hi;
sn
i;
X)
is returned. Then,p
i
enters the meeting room to attendX. After finishing the forum,p
i
returns to statethinking
.When
p
i
+1receives a request messageReq(
hj;
sn
j
i;
X)
fromp
i
, it either forwards the request to its successorp
i
+2, or detains the request in its message queue; the decision depends onp
i
+1’s state.p
i
+1 forwards the request if one of the following conditions is satisfied: (1) it is in statethinking
, (2) it is also interested in X, or (3) it is inter-ested in a different forum and has a priority lower thanp
j
. A philosopher’s priority is assigned as follows: when the philosopher has sent out a requestReq
(
hj;
sn
j
i;
X)
, it ob-tains a priorityhj;
sn
j
i, and it possesses the priority until it has leftX. A priorityhj;
sn
j
iis higher thanhk;
sn
k
i, de-noted byhj;
sn
j
i>
hk;
sn
k
iif, and only if,sn
j
<
sn
k
, orsn
j
= sn
k
andj < k
. For simplicity, we assume that a philosopher’s priority is set to a minimal valuehi;
1iwhen it is not interested in any forum; that is, when it is in statethinking
.On the other hand,
p
i
+1detains the request if none of the above three conditions is satisfied. In other words,p
i
+1 de-tains the request if it is interested in a different forumY
and has a priority higher thanhj;
sn
j
i.p
i
+1detains the request until it has finishedY. Then,p
i
+1forwards the request (and all other requests it has held) to its successorp
i
+2.It can be seen that the algorithm satisfies all three re-quirements of the Congenial Talking Philosophers problem. For mutual exclusion, observe that by the way sequence numbers are maintained, if a philosopher
p
j
requests a fo-rum after it has received a requestReq(
hi;
sn
i;
X)
issued byp
i
, thenp
j
must obtain a priority for its request lower than hi;
sn
i. So, whenp
j
’s request circles top
i
, if the request is for a forum different from X, then the request must be detained byp
i
untilp
i
has finished Xfor its re-questReq(
hi;
sn
i;
X)
. Therefore,p
j
cannot attend a dif-ferent forum whilep
i
is in X. Moreover, given that pri-orities are unique, when two philosophers request different forums concurrently, the request issued by the low-priority philosopher will be detained by the high-priority philoso-pher until the high-priority one has finished a forum. So, the two philosophers cannot be in different forums simulta-neously. Because neither logically dependent requests nor concurrent requests can violate mutual exclusion, mutual exclusion is guaranteed.For bounded delay, observe that a philosopher releases all detained messages to its successor when it finishes a fo-rum. Given that a philosopher spends only a finite time in a forum and that every message will eventually be delivered to its target, a philosopher that has issued a request along the ring will eventually receive the request and, so, will eventu-ally attend a forum.
For concurrent entering, observe that philosophers will not detain one another’s request if they are interested in the same forum. Given that philosophers not interested in a fo-rum will not detain any request, if some philosophers are interested in the same forum and no philosopher is inter-ested in a different forum, then the philosophers can attend the forum concurrently.
We now consider various complexity measures of CTP-Ring1. It is easy to see that the algorithm requires
N
messages for each philosopher to attend a forum. For time and context-switch complexity, we first calculate the maximum number of passages that may proceedp
i
’s pas-sage throughXafterp
i
has made a requestReq
(
hi;
sn
i
i;
X)
. Suppose that another philosopherp
j
has also made a re-questReq(
hj;
sn
j
i;
Y)
. Obviously, ifsn
j
> sn
i
, thenp
j
cannot make a passage throughYuntilp
i
has made a pas-sage throughX(unlessY=
X). So assume thatsn
j
sn
i
. Since messages need not be transmitted in the order sent,p
j
may receive its request whilep
i
’s request is still on the way to, say,p
i
+1. Sop
j
may not have any knowledge aboutp
i
’s sequence numbersn
i
. Therefore,p
j
’s next request may still have a sequence number less than or equal tosn
i
(but greater thansn
j
). Sop
j
can still make another passage be-forep
i
can attendX. Note that even if the sequence number of the new request is equal tosn
i
,p
j
may still attend a fo-rum beforep
i
does ifj < i
. Hence,p
j
can generate at mostsn
i
,sn
j
+ 1
passages beforep
i
can attendX. Note that there is no restriction on the type of forums through which thesn
i
,sn
j
+1
passages are made. So, thesn
i
,sn
j
+1
passages may constitutesn
i
,sn
j
+ 1
rounds.Moreover, by the way sequence numbers are maintained and that every request message must circulate along the ring once, if there is no pending request then all philoso-phers have the same sequence number maintained by their
SN
s. As the maximumSN
in the system increases by 1 only if the philosopher holding this number has initi-ated a new request, in the worst case, the difference be-tween any twoSN
s cannot exceedN
,1
. To reach this case, some philosopher must have initiated a request, yield-ing itsSN
to some numberc
; the request then causes the next philosopher to increase itsSN
toc
+ 1
when initi-ating another request; the second request then causes the next philosopher to increase itsSN
toc
+ 2
when initiat-ing a third request; and so on. So, in the worst case, when some philosopherp
i
has initiated a request with sequence numbersn
, the otherN
,1
philosophers may have all made a request, and have the following sequence numberssn
,(
N
,1)
;
sn
,(
N
,2)
;:::
, andsn
,1
maintained by theirSN
s. Ifp
i
’s ID is the smallest, then, by the previous ar-gument, at mostN
+(
N
,1)+
:::
+2 =
N
2+
N
,22 passages may be initiated before
p
i
can make a passage through a fo-rum. As theN
2+N
,2
2 passages need not overlap or aiming at the same forum, both the time complexity and context-switch complexity of CTP-Ring1 are
O
(
N
2)
.To measure the algorithm’s degree of concurrency, as-sume that
p
j
is in the meeting room, andp
i
is waiting for a different forum. Letsn
be the sequence number ofp
i
’s re-quest. Similar to above argument, the otherN
,2
philoso-phers could all have made a request with sequence numberssn
,(
N
,2)
,sn
,(
N
,3)
;:::
, andsn
,1
. Then, at most(
N
,1) + (
N
,2) +
:::
+ 2 =
N
2 ,
N
,22 passages may be initiated before
p
i
can attend its forum. So the degree of concurrency is alsoO
(
N
2)
.Some simulation results are summarized in Figure 1. In the simulation, we have set up a system of
N
philosophers andm
forums. Each time a philosopher wishes to attend a forum, it randomly chooses one of them
forums to at-tend, and the choice follows a uniform distribution. The time a philosopher stays in statesthinking
andtalking
fol-N
= 30;
thinking= 50ms;
talking= 250ms;
linkdelay= 2msm
= 1m
= 3m
= 10m
= 30 average waiting time (ms) 20.12 6108.46 7292.95 7873.7 average context switches 0 19.08 25.91 28.86 average round size NA 1.51 1.11 1 average capacity 30 1.49 1.11 1 average messages per entry 30 30 30 30 average throughput (entry/sec) 92.13 4.66 3.95 3.67Simulation results for Algorithm CTP-Ring1.
N
= 30;
thinking= 50ms;
talking= 250ms;
linkdelay= 2msm
= 1m
= 3m
= 10m
= 30 average waiting time (ms) 84.92 1538.9 3227.53 7899.85 average context switches 0 1.93 5.34 28.87 average round size NA 14.64 5.37 1 average capacity 30 13.11 5.06 1 average messages per entry 60 60 60 60 average throughput (entry/sec) 76.66 16.06 8.46 3.65Simulation results for Algorithm CTP-Ring2.
Figure 1. Some simulation results
lows an exponential distribution with means
thinking and talking respectively. The message transmission time also follows an exponential distribution with a meanlink delay. For comparison, we have also measured the behavior of the algorithm when philosophers use the meeting room in a mutually exclusive style. This is done by designating one unique forum to each philosopher. In the figure, we usem
=
N
to denote this scenario. We have also set up the case
m
= 1
where maximum concurrency should be al-lowed as no two requests will ever conflict. The average round size measures the average number of passages per round; the average capacity measures, in average, the max-imum number of philosophers that can be in the meeting room simultaneously per round. It is not difficult to see that the settings in the figure represent a very high contention situation to the meeting room. From the tables we can see that CTP-Ring1 provides virtually no concurrency. For ex-ample, whenm
= 3
, it is likely that one third of the pending requests are targeting at the same forum very often. How-ever, the simulation results indicate that the behavior of the system is only slightly better than the casem
= 30
where the philosophers use the meeting room in a mutually exclu-sive style!2
To see why CTP-Ring1 has such a poor performance, observe that philosophers’ requests are granted according to their priorities: a high-priority philosopher must enter the meeting room before a low-priority one. As a result, suppose that a number of philosophers are interested in two different forums (say,XandY), and their priorities are or-dered in such a way that two consecutive philosophers in the ordering are interested in different forums (that is, the first philosopher is interested inX, the second philosopher is interested inY, the third philosopher is interested inX, the fourth philosopher is interested inY, and so on.) Then, the philosophers would proceed their forums in a purely in-terleaving and sequential style: the first philosopher
estab-2Some Java applets animating the algorithms for the Congenial
Talking Philosophers problem presented in the paper can be found in
lishes forumX, then the second philosopher establishes fo-rumY, then the third philosopher establishes forumX, then the fourth philosopher establishes forumY, and so on. Note that, for this case no concurrency is allowed by the algo-rithm because only one philosopher can be in a forum at a time, albeit there are several other philosophers interested in the same forum. In the following section we present a modification of the algorithm that requires
2
N
messages per request, but offers a much better performance.4
An Improved Algorithm
As discussed above, the low concurrency of CTP-Ring1 is due to the fact that, if two philosophers
p
i
andp
j
are inter-ested in the same forum but there is a third philosopherp
k
interested in a different forum and has a priority in betweenp
i
andp
j
, thenp
i
andp
j
cannot attend the same forum concurrently because the low-priority philosopherp
j
must wait forp
k
to finish a forum before it can attend a forum. Our solution for the problem is to letp
i
issue another mes-sage along the ring to “capture”p
j
(and other philosophers that are also interested in the same forum) so that the cap-tured philosophers can attend the forum concurrently with the captor.To do so, we introduce a new state
checking
for the philosophers. As before, a philosopher’s priority is set to hi;
sn
iwhen it issues a requestReq
(
hi;
sn
i;
X)
. However, the priority may be “upgraded” (but at most once) before the philosopher attends forumX. The priority is reset to a minimal valuehi;
1iwhen the philosopher returns to statethinking
. (Thus, a philosopher carries a priority all the time. In particular, its priority in statethinking
is always lower than that of a philosopher interested in a forum.)Like the previous algorithm, when a philosopher
p
i
wishes to attend a forum X, it enters statewaiting
, in-crements itsSN
by 1, and sends a request messageReq
(
hi;
sn
i;
X)
to its successorp
i
+1, wheresn
is the new value ofp
i
’sSN
. Another philosopherp
j
in the ring, upon receiving the request, forwards the request if it is also in-terested inXor has a priority lower thanhi;
sn
i; otherwise,p
j
detains the request in its message queue until it has fin-ished a forum. When the request is returned top
i
,p
i
enters statechecking
to issue a confirmation message of the formConrm C
(
hi;
sn
i;
X)
to its successorp
i
+1. The purpose of the message is twofold: to capture philosophers that are waiting forX, and to make sure that no philosopher is still in a different forum. Philosopherp
i
must wait until the mes-sage is returned before it can attendX.When a philosopher
p
j
receivesConrm C
(
hi;
sn
i;
X)
, wherej
6=
i
, it processes the message similarly as request messages:p
j
forwards the request if it is also interested inX or has a priority lower thanhi;
sn
i; otherwise,p
j
detains the request. Note that all messages (requests and confirmations) detained by a philosopher are released when the philosopher has finished a forum. In addition, ifp
j
is also interested in X, is in statewaiting
, and has a priority lower thanhi;
sn
i, thenp
j
is captured byp
i
. In this case,p
j
assumesp
i
’s priority and also enters statechecking
to issue a confirma-tion message of the formConrm(
j;
hi;
sn
i;
X)
along the ring. (p
j
’s request message circulating somewhere in thering then becomes obsolete.) Unlike
p
i
’s confirmation mes-sage,p
j
’s confirmation message serves only one purpose: to make sure that no philosopher is still in a different fo-rum. Therefore, a philosopher receivingp
j
’s confirmation message processes the message similarly to the other form of confirmation messages (i.e.,Conrm C
, where “ C” means “with capturing”), except that the new form of confir-mation messages cannot capture the receiving philosophers. This preventsp
j
from capturingp
i
afterp
i
has attendedX and has made a new request to re-attendX, thereby prevent-ingp
i
andp
j
from capturing each other repeatedly (which could also result in a violation of mutual exclusion).Philosopher
p
i
enters statetalking
to attendXwhen its confirmation messageConrm C
(
hi;
sn
i;
X)
is returned. Afterp
i
has finished the forum, it forwards all the messages it has detained to its successorp
i
+1and then returns to statethinking
. Note that because some low-priority philoso-phers may have been captured byp
i
to concurrently attend X, afterp
i
has exitedX, some philosophers may still be inX while another philosopherp
k
whose priority is higher than the captured philosophers is waiting for a different forum Y. Moreover, becausep
i
will release all messages held in its message queue when it exitsX,p
k
may have received its own requestReq(
hk;
sn
0
i
;
Y)
afterp
i
has exitedXbut before all the philosophers captured byp
i
have exitedX. Therefore,p
k
cannot immediately enter statetalking
to at-tendY when it receives its own request. Instead, it must initiate a confirmation messageConrm C
(
hk;
sn
0 i
;
Y)
to make sure that allp
i
’s captured philosophers have exitedX. Similarly, any philosopher captured byp
k
during the timep
k
’s confirmation message is circulating must also initiate a confirmation message (of the formConrm
) along the ring before it can enter statetalking
to attend a forum.We refer to the new algorithm as CTP-Ring2, and its complete code is given in Figure 2. The algorithm is repre-sented by a CSP-like repetitive command of the form [1]:
[
g
1!s
12g
2!s
22:::
2g
k
!s
k
]
The guarded command
s
i
is executed only if its guardg
i
isenabled: The Boolean expression (if any) evaluates to true
and the message specified in the guard (if any) has arrived. If more than one guarded command have an enabled guard, then one of them is chosen for execution, and the choice is nondeterministic. We assume that a guarded command whose guard is continuously enabled will eventually be ex-ecuted.
It is not difficult to see that CTP-Ring2 satisfies mutual exclusion, bounded delay, and concurrent entering. Due to the space limitation, the correctness of the algorithm is proved in the full paper [6]. The algorithm has similar complexity measures as CTP-Ring1; that is, its time complexity, context-switch complexity, and degree of concurrency are all of
O
(
N
2)
. Again, the analysis can be found in the full paper. We remark here that, by a simple modification, the context-switch complexity of CTP-Ring2 can be further reduced tomin(
N;m
+1)
. To do so, request messages now have this form:
Req
(
hi;
sn
i;
sn
max;
X)
where the extra sequence number
sn
maxcarried by the re-quest is the maximum sequence number of the philoso-phers through which the request has passed. Initially,sn
max1 *[wish to attend a forum ofX,!
2
SN
:=
SN
+ 1
; 3target
:=
X;4
priority
:=
hi;SN
i;5
state
:=
waiting
;6 send
Req
(
hi;SN
i;X)
topi+1;7 2receive
Req
(
hj;sn
i;Y)
,! 8SN
:= max(
SN
;sn
)
; 9 [ i=
j Vstate
=
waiting
Vpriority
=
hj;sn
i,! 10state
:=
checking
;11 send
Conrm C
(
hi;sn
i;target
)
top i+1; 12 2i6=
j V(
target
=
Y W(
priority
<hj;sn
i)
,! 13 sendReq
(
hj;sn
i;Y)
top i+1; 14 2i6=
j Vtarget
6=
Y Vpriority
>hj;sn
i ,!15 add
Req
(
hj;sn
i;Y)
tomessage queue
;16 2else,!skip; /*p
ireceives its own obsolete request */ ]
172receive
Conrm C
(
hj;sn
i;Y)
,!18 [ i
=
j,!/* receivepi’s own confirmation message */19
state
:=
talking
; 20 attend a forum oftarget
; 21 2i6=
jV
target
6=
Y Vpriority
>hj;sn
i,!22 add
Conrm C
(
hj;sn
i;Y)
tomessage queue
;23 2else,!send
Conrm C
(
hj;sn
i;Y)
topi+1;24 [
target
=
Y Vstate
=
waiting
Vpriority
<hj;sn
i,!25
state
:=
checking
; /* captured bypj*/26
priority
:=
hj;sn
i; /* assume the captor’s priority */27 send
Conrm
(
i;hj;sn
i;target
)
top i+1; ] ]282receive
Conrm
(
j;hk;sn
i;Y)
,!29 [ i
=
j,!/* receivepi’s own confirmation message */
30
state
:=
talking
; 31 attend a forum oftarget
; 32 2i6=
jV
target
6=
Y Vpriority
>hk;sn
i,!33 add
Conrm
(
j;hk;sn
i;Y)
tomessage queue
;34 2else,!send
Conrm
(
j;hk;sn
i;Y)
topi+1; ]352exit a forum of
target
,!36
state
:=
thinking
; 37target
:=
?;38
priority
:=
hi;1i; /* reset the priority to a minimal value */39 for each
msg
2message queue
do sendmsg
top i+1;40
message queue
:=
;;41
]
variables & messages:
state
: the state of pi. Its value ranges over
f
thinking
,waiting
,checking
,talking
g, and is initialized tothinking
.SN
: the sequence number maintained bypi. It is initialized
to
0
.
target
: the forumpiwishes to attend, or?otherwise. It isinitialized to?.
priority
: pi’s priority. It is initialized to a minimal value hi;1i.
message queue
: the queue of messages detained bypi. Itis initialized to empty.
Req
(
hi;sn
i;X)
: a request message bypito attend a forum X, wherehi;
sn
iispi’s priority when it makes the request.
Conrm C
(
hi;sn
i;X)
: a confirmation message issuedbyp
i(with priority
hi;
sn
i) to capture philosophers and tomake sure that no philosopher is still in a different forum.
Conrm
(
i;hj;sn
i;X)
: a confirmation message issued by pi to make sure that no philosopher is still in a differentforum. hj;
sn
iis the priority ofpiassumed from its captor p
j.
Figure 2. AlgorithmCTP-Ring2for
p
i
.equals to
p
i
’sSN
whenp
i
issues the request (and note thatsn
is also equal top
i
’sSN
). Upon receiving the request, a philosopherp
j
adjusts its ownSN
to be maximum value of its currentSN
andsn
max. Whenp
j
is to forward the request to its successor (in the case thati
6=
j
), it adjustssn
maxto be maximum value of its currentSN
andsn
max. (Note that if the request is to be held byp
j
, then in between the timep
j
receives the request and the time it releases the request,p
j
’s sequence numberSN
may have been adjusted a number of times.)An extra sequence number is also added to confirmation messages so that they now have one of the following two forms:
Conrm C
(
hi;
sn
i;
sn
max;
X)
Conrm(
i;
hj;
sn
i;
sn
max;
X)
.The extra parameter
sn
maxis initialized and used as in the new request messages.The simulation results of the new algorithm are also given in Figure 1. From the results we can see that the new algorithm significantly improves the performance of CTP-Ring1.
5
Conclusions
We have presented two distributed algorithms CTP-Ring1 and CTP-Ring2 for the Congenial Talking Philosophers problem on a ring network where each philosopher can only communicate directly with its two neighboring philosophers. CTP-Ring1 requires
N
messages per entry to the meeting room, and the time complexity, context-switch complexity, and degree of concurrency are allO
(
N
2)
, whereN
is the total number of philosophers in the ring. In contrast, CTP-Ring2 requires2
N
messages, has alsoO
(
N
2)
time complexity and degree of concurrency, but has a better context-switch complexity ofmin(
N;m
+ 1)
, wherem
is the total number of forums the philosophers may attend. Although, statically, the two algorithms do not differ very much from various complexity measures, the difference between their dynamic performance is significant. As we have shown in the simulation, CTP-Ring1 performs poorly as compared to CTP-Ring2; it out-performs CTP-Ring2 only in message complexity.References
[1] C. A. R. Hoare. Communicating sequential processes. CACM, 21(8):666–677, Aug. 1978.
[2] Y.-J. Joung. Asynchronous group mutual exclusion (extended abstract). In Proc. 17th ACM PODC, pp. 51-60, 1998. [3] Y.-J. Joung. The congenial talking philosophers problem in
computer networks. Technical report, Dept. of Info. Manage-ment, National Taiwan University, Taipei, Taiwan, 1998. [4] L. Lamport. Time, clocks and the ordering of events in a
distributed system. CACM, 21(7):558–565, July 1978. [5] A. M. Law and W. D. Kelton. Simulation modeling &
analy-sis. McGraw-Hill, 1991.
[6] K.-P. Wu and Y.-J. Joung. Asynchronous group mutual exclu-sion in ring networks. Technical report, Dept. of Info. Man-agement, National Taiwan University, Taipei, Taiwan, 1999.