• 沒有找到結果。

Asynchronous group mutual exclusion in ring networks

N/A
N/A
Protected

Academic year: 2021

Share "Asynchronous group mutual exclusion in ring networks"

Copied!
5
0
0

加載中.... (立即查看全文)

全文

(1)

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

philosophers

p

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

philosophers

p

0

;p

1

;::: ;p

N

,1are connected via a ring net-work so that each philosopher

p

i

can only send messages directly to its immediate successor

p

i

+1. (Unless stated, otherwise, additions and subtractions on indices of philoso-phers are to be interpreted modulo

N

.) 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:

(2)

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 by

p

i

to be an interval

[

t

1

;t

2

]

, where

t

1 is the time

p

i

en-ters the meeting room to attendX, and

t

2is the time it exits the meeting room. The attribute of the passage is denoted byh

p

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 at

t

1, and is completed at

t

2. The passage is ongoing at any time in between

t

1and

t

2.

Let

T

be the set of passages that may be initiated after a philosopher

p

i

has made a request for a forum, and that must be completed before

p

i

can enter the meeting room. The time complexity is measured by

(

T

)

, where

(

T

)

is the size of a minimal set

R



T

such that for every passage

2

T

, every time instance in

is contained in some

2

R

. 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 which

p

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; and

talking

, meaning that it is in a forum. Moreover, each philosopher maintains a variable

SN

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 its

SN

to 0 and, whenever it learns of a sequence number larger than its own

SN

, it advances its

SN

to that number. Furthermore, a philosopher increments its

SN

by 1 when it wishes to attend a forum.

Initially, every philosopher is in state

thinking

. When a philosopher

p

i

wishes to attend a forumX, it enters state

waiting

, increments its

SN

by 1, and sends a request mes-sage

Req

(

h

i;

sn

i

;

X

)

to its successor

p

i

+1, where

sn

is the

new value of

p

i

’s

SN

. Philosopher

p

i

remains in state

waiting

until its request

Req

(

h

i;

sn

i

;

X

)

is returned. Then,

p

i

enters the meeting room to attendX. After finishing the forum,

p

i

returns to state

thinking

.

When

p

i

+1receives a request message

Req(

h

j;

sn

j

i

;

X

)

from

p

i

, it either forwards the request to its successor

p

i

+2, or detains the request in its message queue; the decision depends on

p

i

+1’s state.

p

i

+1 forwards the request if one of the following conditions is satisfied: (1) it is in state

thinking

, (2) it is also interested in X, or (3) it is inter-ested in a different forum and has a priority lower than

p

j

. A philosopher’s priority is assigned as follows: when the philosopher has sent out a request

Req

(

h

j;

sn

j

i

;

X

)

, it ob-tains a priorityh

j;

sn

j

i, and it possesses the priority until it has leftX. A priorityh

j;

sn

j

iis higher thanh

k;

sn

k

i, de-noted byh

j;

sn

j

i

>

h

k;

sn

k

iif, and only if,

sn

j

<

sn

k

, or

sn

j

= sn

k

and

j < k

. For simplicity, we assume that a philosopher’s priority is set to a minimal valueh

i;

1iwhen it is not interested in any forum; that is, when it is in state

thinking

.

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 forum

Y

and has a priority higher thanh

j;

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 successor

p

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 request

Req(

h

i;

sn

i

;

X

)

issued by

p

i

, then

p

j

must obtain a priority for its request lower than h

i;

sn

i. So, when

p

j

’s request circles to

p

i

, if the request is for a forum different from X, then the request must be detained by

p

i

until

p

i

has finished Xfor its re-quest

Req(

h

i;

sn

i

;

X

)

. Therefore,

p

j

cannot attend a dif-ferent forum while

p

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

(3)

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 proceed

p

i

’s pas-sage throughXafter

p

i

has made a request

Req

(

h

i;

sn

i

i

;

X

)

. Suppose that another philosopher

p

j

has also made a re-quest

Req(

h

j;

sn

j

i

;

Y

)

. Obviously, if

sn

j

> sn

i

, then

p

j

cannot make a passage throughYuntil

p

i

has made a pas-sage throughX(unlessY

=

X). So assume that

sn

j



sn

i

. Since messages need not be transmitted in the order sent,

p

j

may receive its request while

p

i

’s request is still on the way to, say,

p

i

+1. So

p

j

may not have any knowledge about

p

i

’s sequence number

sn

i

. Therefore,

p

j

’s next request may still have a sequence number less than or equal to

sn

i

(but greater than

sn

j

). So

p

j

can still make another passage be-fore

p

i

can attendX. Note that even if the sequence number of the new request is equal to

sn

i

,

p

j

may still attend a fo-rum before

p

i

does if

j < i

. Hence,

p

j

can generate at most

sn

i

,

sn

j

+ 1

passages before

p

i

can attendX. Note that there is no restriction on the type of forums through which the

sn

i

,

sn

j

+1

passages are made. So, the

sn

i

,

sn

j

+1

passages may constitute

sn

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 maximum

SN

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 two

SN

s cannot exceed

N

,

1

. To reach this case, some philosopher must have initiated a request, yield-ing its

SN

to some number

c

; the request then causes the next philosopher to increase its

SN

to

c

+ 1

when initi-ating another request; the second request then causes the next philosopher to increase its

SN

to

c

+ 2

when initiat-ing a third request; and so on. So, in the worst case, when some philosopher

p

i

has initiated a request with sequence number

sn

, the other

N

,

1

philosophers may have all made a request, and have the following sequence numbers

sn

,

(

N

,

1)

;

sn

,

(

N

,

2)

;:::

, and

sn

,

1

maintained by their

SN

s. If

p

i

’s ID is the smallest, then, by the previous ar-gument, at most

N

+(

N

,

1)+

:::

+2 =

N

2+

N

,2

2 passages may be initiated before

p

i

can make a passage through a fo-rum. As the

N

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, and

p

i

is waiting for a different forum. Let

sn

be the sequence number of

p

i

’s re-quest. Similar to above argument, the other

N

,

2

philoso-phers could all have made a request with sequence numbers

sn

,

(

N

,

2)

,

sn

,

(

N

,

3)

;:::

, and

sn

,

1

. Then, at most

(

N

,

1) + (

N

,

2) +

:::

+ 2 =

N

2 ,

N

,2

2 passages may be initiated before

p

i

can attend its forum. So the degree of concurrency is also

O

(

N

2

)

.

Some simulation results are summarized in Figure 1. In the simulation, we have set up a system of

N

philosophers and

m

forums. Each time a philosopher wishes to attend a forum, it randomly chooses one of the

m

forums to at-tend, and the choice follows a uniform distribution. The time a philosopher stays in states

thinking

and

talking

fol-N

= 30

; 

thinking= 50ms

; 

talking= 250ms

; 

linkdelay= 2ms

m

= 1

m

= 3

m

= 10

m

= 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.67

Simulation results for Algorithm CTP-Ring1.

N

= 30

; 

thinking= 50ms

; 

talking= 250ms

; 

linkdelay= 2ms

m

= 1

m

= 3

m

= 10

m

= 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.65

Simulation 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 mean



link 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 use

m

=

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, when

m

= 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 case

m

= 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

(4)

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

and

p

j

are inter-ested in the same forum but there is a third philosopher

p

k

interested in a different forum and has a priority in between

p

i

and

p

j

, then

p

i

and

p

j

cannot attend the same forum concurrently because the low-priority philosopher

p

j

must wait for

p

k

to finish a forum before it can attend a forum. Our solution for the problem is to let

p

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 h

i;

sn

iwhen it issues a request

Req

(

h

i;

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 valueh

i;

1iwhen the philosopher returns to state

thinking

. (Thus, a philosopher carries a priority all the time. In particular, its priority in state

thinking

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 state

waiting

, in-crements its

SN

by 1, and sends a request message

Req

(

h

i;

sn

i

;

X

)

to its successor

p

i

+1, where

sn

is the new value of

p

i

’s

SN

. Another philosopher

p

j

in the ring, upon receiving the request, forwards the request if it is also in-terested inXor has a priority lower thanh

i;

sn

i; otherwise,

p

j

detains the request in its message queue until it has fin-ished a forum. When the request is returned to

p

i

,

p

i

enters state

checking

to issue a confirmation message of the form

Con rm C

(

h

i;

sn

i

;

X

)

to its successor

p

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. Philosopher

p

i

must wait until the mes-sage is returned before it can attendX.

When a philosopher

p

j

receives

Con rm C

(

h

i;

sn

i

;

X

)

, where

j

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 thanh

i;

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, if

p

j

is also interested in X, is in state

waiting

, and has a priority lower thanh

i;

sn

i, then

p

j

is captured by

p

i

. In this case,

p

j

assumes

p

i

’s priority and also enters state

checking

to issue a confirma-tion message of the form

Con rm(

j;

h

i;

sn

i

;

X

)

along the ring. (

p

j

’s request message circulating somewhere in the

ring 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 receiving

p

j

’s confirmation message processes the message similarly to the other form of confirmation messages (i.e.,

Con rm C

, where “ C” means “with capturing”), except that the new form of confir-mation messages cannot capture the receiving philosophers. This prevents

p

j

from capturing

p

i

after

p

i

has attendedX and has made a new request to re-attendX, thereby prevent-ing

p

i

and

p

j

from capturing each other repeatedly (which could also result in a violation of mutual exclusion).

Philosopher

p

i

enters state

talking

to attendXwhen its confirmation message

Con rm C

(

h

i;

sn

i

;

X

)

is returned. After

p

i

has finished the forum, it forwards all the messages it has detained to its successor

p

i

+1and then returns to state

thinking

. Note that because some low-priority philoso-phers may have been captured by

p

i

to concurrently attend X, after

p

i

has exitedX, some philosophers may still be inX while another philosopher

p

k

whose priority is higher than the captured philosophers is waiting for a different forum Y. Moreover, because

p

i

will release all messages held in its message queue when it exitsX,

p

k

may have received its own request

Req(

h

k;

sn

0

i

;

Y

)

after

p

i

has exitedXbut before all the philosophers captured by

p

i

have exitedX. Therefore,

p

k

cannot immediately enter state

talking

to at-tendY when it receives its own request. Instead, it must initiate a confirmation message

Con rm C

(

h

k;

sn

0 i

;

Y

)

to make sure that all

p

i

’s captured philosophers have exitedX. Similarly, any philosopher captured by

p

k

during the time

p

k

’s confirmation message is circulating must also initiate a confirmation message (of the form

Con rm

) along the ring before it can enter state

talking

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

12

g

2!

s

22

:::

2

g

k

!

s

k

]

The guarded command

s

i

is executed only if its guard

g

i

is

enabled: 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 to

min(

N;m

+1)

. To do so, request messages now have this form:



Req

(

h

i;

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

max

(5)

1 *[wish to attend a forum ofX,!

2

SN

:=

SN

+ 1

; 3

target

:=

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

)

,! 8

SN

:= max(

SN

;

sn

)

; 9 [ i

=

j V

state

=

waiting

V

priority

=

hj;

sn

i,! 10

state

:=

checking

;

11 send

Con rm C

(

hi;

sn

i;

target

)

top i+1; 12 2i6

=

j V

(

target

=

Y W

(

priority

<hj;

sn

i

)

,! 13 send

Req

(

hj;

sn

i;Y

)

top i+1; 14 2i6

=

j V

target

6

=

Y V

priority

>hj;

sn

i ,!

15 add

Req

(

hj;

sn

i;Y

)

to

message queue

;

16 2else,!skip; /*p

ireceives its own obsolete request */ ]

172receive

Con rm C

(

hj;

sn

i;Y

)

,!

18 [ i

=

j,!/* receivepi’s own confirmation message */

19

state

:=

talking

; 20 attend a forum of

target

; 21 2i6

=

j

V

target

6

=

Y V

priority

>hj;

sn

i,!

22 add

Con rm C

(

hj;

sn

i;Y

)

to

message queue

;

23 2else,!send

Con rm C

(

hj;

sn

i;Y

)

topi+1;

24 [

target

=

Y V

state

=

waiting

V

priority

<hj;

sn

i,!

25

state

:=

checking

; /* captured bypj*/

26

priority

:=

hj;

sn

i; /* assume the captor’s priority */

27 send

Con rm

(

i;hj;

sn

i;

target

)

top i+1; ] ]

282receive

Con rm

(

j;hk;

sn

i;Y

)

,!

29 [ i

=

j,!/* receivep

i’s own confirmation message */

30

state

:=

talking

; 31 attend a forum of

target

; 32 2i6

=

j

V

target

6

=

Y V

priority

>hk;

sn

i,!

33 add

Con rm

(

j;hk;

sn

i;Y

)

to

message queue

;

34 2else,!send

Con rm

(

j;hk;

sn

i;Y

)

topi+1; ]

352exit a forum of

target

,!

36

state

:=

thinking

; 37

target

:=

?;

38

priority

:=

hi;1i; /* reset the priority to a minimal value */

39 for each

msg

2

message queue

do send

msg

top i+1;

40

message queue

:=

;;

41

]

variables & messages:



state

: the state of p

i. Its value ranges over

f

thinking

,

waiting

,

checking

,

talking

g, and is initialized to

thinking

. 

SN

: the sequence number maintained byp

i. It is initialized

to

0

.



target

: the forumpiwishes to attend, or?otherwise. It is

initialized to?.



priority

: pi’s priority. It is initialized to a minimal value hi;1i.



message queue

: the queue of messages detained bypi. It

is initialized to empty.



Req

(

hi;

sn

i;X

)

: a request message byp

ito attend a forum X, wherehi;

sn

iisp

i’s priority when it makes the request. 

Con rm C

(

hi;

sn

i;X

)

: a confirmation message issued

byp

i(with priority

hi;

sn

i) to capture philosophers and to

make sure that no philosopher is still in a different forum.



Con rm

(

i;hj;

sn

i;X

)

: a confirmation message issued by pi to make sure that no philosopher is still in a different

forum. hj;

sn

iis the priority ofp

iassumed from its captor p

j.

Figure 2. AlgorithmCTP-Ring2for

p

i

.

equals to

p

i

’s

SN

when

p

i

issues the request (and note that

sn

is also equal to

p

i

’s

SN

). Upon receiving the request, a philosopher

p

j

adjusts its own

SN

to be maximum value of its current

SN

and

sn

max. When

p

j

is to forward the request to its successor (in the case that

i

6

=

j

), it adjusts

sn

maxto be maximum value of its current

SN

and

sn

max. (Note that if the request is to be held by

p

j

, then in between the time

p

j

receives the request and the time it releases the request,

p

j

’s sequence number

SN

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:



Con rm C

(

h

i;

sn

i

;

sn

max

;

X

)



Con rm(

i;

h

j;

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 all

O

(

N

2

)

, where

N

is the total number of philosophers in the ring. In contrast, CTP-Ring2 requires

2

N

messages, has also

O

(

N

2

)

time complexity and degree of concurrency, but has a better context-switch complexity of

min(

N;m

+ 1)

, where

m

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.

數據

Figure 2. Algorithm CTP-Ring2 for p i .

參考文獻

相關文件

After the Opium War, Britain occupied Hong Kong and began its colonial administration. Hong Kong has also developed into an important commercial and trading port. In a society

Now, nearly all of the current flows through wire S since it has a much lower resistance than the light bulb. The light bulb does not glow because the current flowing through it

好了既然 Z[x] 中的 ideal 不一定是 principle ideal 那麼我們就不能學 Proposition 7.2.11 的方法得到 Z[x] 中的 irreducible element 就是 prime element 了..

Two distinct real roots are computed by the Müller’s Method with different initial points... Thank you for

The Hilbert space of an orbifold field theory [6] is decomposed into twisted sectors H g , that are labelled by the conjugacy classes [g] of the orbifold group, in our case

To complete the “plumbing” of associating our vertex data with variables in our shader programs, you need to tell WebGL where in our buffer object to find the vertex data, and

Following the supply by the school of a copy of personal data in compliance with a data access request, the requestor is entitled to ask for correction of the personal data

request even if the header is absent), O (optional), T (the header should be included in the request if a stream-based transport is used), C (the presence of the header depends on