Chang 1996 Micro Processing and Micro Programming

download Chang 1996 Micro Processing and Micro Programming

of 17

Transcript of Chang 1996 Micro Processing and Micro Programming

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    1/17

    ELSEVIER

    MicroprocessingandMicroprogramming

    Microprocessing and Microprogramming 41 ( 1996) 715-73 1

    A hybrid distributed mutual exclusion algorithm Ye-In Chang 2

    Dept. of Applied M athemat ics, Nat ional Sun Yat-Sen University , Kaohsiung, Taiw an, RO CReceived 16 December 1993; revised 8 November 1995.9 January 1996; accepted 24 January 1996

    AbstractThis paper presents a hybrid approach to distributed mutual exclusion in which two algorithms are combined such thatone minimizes message traffic and the other minimizes time delay. In a hybrid approach, sites are divided into groups, and

    two different algorithms are used to resolve local (in&a-group) and global (inter-group) conflicts. In this paper, we developa hybrid distributed mutual exclusion algorithm which uses Singhals dynamic information structure algorithm [ 151 as thelocal algorithm to minimize time delay and Maekawas algorithm [7] as the global algorithm to minimize message traffic.Compared to Maekawas algorithm which needs O(a) messages, but two time units delay between successive executionsof the Critical Section (CS) (where N is the number of sites in the system), the proposed hybrid algorithm can reducemessage traffic by 52% and time delay by 29% at the same time.Keywords: Critical section; Distributed algorithms; Hybrid algorithms; locality; Mutual exclusion; Synchronization

    1. IntroductionA distributed system consists of a collection of geo-graphically dispersed autonomous sites connected by

    a communication network. The sites have no sharedmemory and communicate with one another by pass-ing messages. Message propagation time delay is fi-nite but unpredictable. In this paper, we assume thatthe communication subsystem is reliable and sites do

    This research was supported by the National Science Councilof the Republic of China, Grant No. NSC-81-0408-E-110-508. Email: [email protected]

    not crash. Moreover, between any pair of sites, mes-sages are delivered in the order in which they are sent.

    In the problem of mutual exclusion, concurrent ac-cess to a shared resource or the Critical Section (CS)must be synchronized such that at any time only oneprocess can access the CS [3,4]. In general, algo-rithms to distributed mutual exclusion can be classifiedinto two classes: token-based and non-token-based. Intoken-based algorithms [ 5,8-10,14,16,17], only thesite holding the token can execute the CS and makesthe final decision on the next site to enter the CS. Innon-token-based algorithms [ 1,2,6,7,12,13,15], a re-questing site can execute the CS only after it has re-

    016%6074/96/$15.00 @ 1996 Elsevier Science B.V. All rights reservedPII SOl65-6074(96)00013-O

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    2/17

    716 Y.-I. Chang/Microprocessing and Microprogramm ing 1 (1996) 715-731ceived permission from each member of a subset ofsites in the system, and every site receiving a CS re-quest message participates in making the final deci-sion.

    Among these token-based algorithms, Suzuki andKasamis algorithm [ 161 and Nishio et al.s algorithm[ 91 require 0 or N messages and two time units delayper CS execution, where N is the number of sites in thesystems. Singhals heuristically-aided algorithm [ 141requires between 0 and N messages, but may needmore than two time units delay since all of the neededRequest messages may not be sent out simultaneously.Trehel and Naimis algorithms [ 8,171 require onlyO( log N) messages, but need longer time delay sinceRequest messages are forwarded serially. Raymondsalgorithm [ IO] also requires only O( log N) messages,but needs much longer time delay since both Requestand Token messages are propagated serially.

    Among these non-token-based algorithms, Lam-ports algorithm [ 61 requires 3 * (N - 1) messagesand two time units delay. Ricart and Agrawalas algo-rithm [ 121 requires 2 * (N - 1) messages and similartime delay as Lamports algorithm. Both Carvalhoand Roucairols algorithm [ 1 ] and Singhals dynamicinformation structure algorithm [ 151 require between0 and 2 * (N - 1) messages, but may need morethan two time units delay since all of the needed Re-quest messages may not be sent out simultaneously.Maekawas algorithm [2,7] requires only 0( fi>messages, and two time units delay to enter the CS;however, this algorithm needs one more time delayto release the locked site which then can send a Re-ply message to one of other requesting sites. That is,Maekawas algorithm doubles the time delay in suc-cessive executions of CS as compared to [ 1,6,12,151.

    Therefore, there is no single algorithm that can min-imize both message traffic and time delay at the sametime. Most algorithms reduce message traffic by in-creasing time delay. To minimize both message trafficand time delay at the same time, we must look for a hy-brid approach to mutual exclusion in which two algo-rithms are combined such that one minimizes message

    traffic and the other minimizes time delay. In this pa-per, we present a hybrid approach to mutual exclusionfor distributed systems. In a hybrid approach, sites aredivided into groups, and two different algorithms areused to resolve local (intra-group) and global (inter-group) conflicts. That is, sites use one local algorithmto resolve conflicts with sites in the same group anduse a different global algorithm to resolve conflictswith sites in the other groups. To design a correct andefficient hybrid algorithm, several design issues mustbe addressed to control the interaction between the lo-cal and global algorithms. Based on these design is-sues, we develop a hybrid distributed mutual exclusionalgorithm which uses Singhals dynamic informationstructure algorithm [ 151 as the local algorithm to min-imize time delay and Maekawas algorithm [2,7] asthe global algorithm to minimize message traffic.

    The rest of the paper is organized as follows. Section2 defines the request sets in a hybrid approach to mu-tual exclusion. Section 3 describes the design issues.Section 4 presents a hybrid algorithm which uses Sing-hals dynamic information structure algorithm [ 151 asthe local algorithm and Maekawas algorithm [ 71 asthe global algorithm. Section 5 shows the correctnessof the hybrid algorithm. Section 6 studies the perfor-mance of the hybrid algorithm using a simulation tech-nique. Finally, Section 7 contains concluding remarks.

    2. Definition of request setsIn this section, we describe notations and defini-

    tions of request sets in a hybrid approach to mutualexclusion.2.1. Notations and dejinitions

    N sites of a distributed system are divided into gdisjoint groups, Group], Groupz, . Group,, and N =Cf=i [Group,/ (f or convenience, we let all groups havethe same number of sites). A request set Rs of siteS is used to record the identifiers of those sites to

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    3/17

    Y.-I. Chang/ Microprocessing and Microprogrdfflihing 41 (1996) 715-731 717which site S must send Request messages to acquirepermission to execute the CS. In a hybrid approach,a request set Rs consists of two sets: a local set LSand a global set Gs. A local set Ls is used to enforcemutual exclusion locally (i.e., within the group) anda global set Gs is used to enforce mutual exclusionglobally (i.e., among the groups). The choice of theidentifiers of the sites in Ls and Gs must satisfy thefollowing conditions:1. Ls n Ly f 4, Vs,Y E GroupK.2. Ls n Ly = 4, Vs E Group,, VY E Group, (K #

    to enforce muturil exclusion among groups) is con-cerned, it treats each group as a site and the LRS actsa8 the site identifier for a group. The global set Gs con-tains a s&b of LRS,s, 1 5 j < g, and the numberof LRSs in each ds is determined according to theglobal algorithm such that the condition Gs nGr # 4(VS E GroupK, VY E Groupp, K + P) is always truebetween different groups. Moreover, every site S inthe same group has the same value of Gs. Therefore,the identifiers of the sites in Gs are determined suchthat conditions 3 and 4 are satisfied.

    P).3. Gs = Gr, Vs,Y E Group,.4. GsnGy f 4, QS E GroupK, VY E Group, (K #P).

    One necessary condition of mutual exclusion in adish&u&d system is RsflRy # 4 [ 7,131, for any twosites S and Y. Based on the definitions, the intersectionof Rs and Rr isTo satisfy conditions 1 and 2, the local sets in eachGroupK of lGroupKl sites are initialized according to

    the local algorithm; therefore, Ls n LY f 4, Vs,Y EGroup,, 1 < K 5 g. Since we divide N sites into gdisjoint groups, Ls n Lr = 4, VS E Group,+ tlY 6Group,, (K # P) . To satisfy conditions 3 and 4, thefollowing definition is needed:

    Rs n RY = (Ls U Gs) n (Ly U Gy)=(LsC7Lv)U(LsnGu)U(GsnLy)

    u (GsnGr).

    Definition 1. LRSK: A Local Representative Set(LRS) of Group, is used to record the identifiers ofa subset of sites in Group,. These are the sites whichgrant global permission to sites in the other groups asfar as Group, is concerned.

    According to the definitions, if S and Y are in thesame group, Ls tl Ly # 4; if S and Y are in differentgtuiqb, La n Ly = C$nd Gs n GY # c$.Therefore,the defitritian of request sets in a hybrid approach sat-isfies the necessary condition of a distributed mutualexclusion algorithm.2.2. An example

    Sites in the LRS of a group have the responsibil-ity of granting global permission to sites in the othergroups. They are the intermediary/interface betweenthis group and other groups. The size of an LRS canvary from 1 to the size of a group, i.e., (N/g). De-pending on the global algorithm used, the identifiersof the sites in each LRS are determined such that thosesites can mediate conflicts between their own groupand the other groups.

    In this section, we give an example of initializa-tion of request sets which uses Maekawas algorithm[2,7] as the global algorithm and Singhals dynamicinformation structure algorithm [ 151 as the local al-gorithm. Since both algorithms will be used in theproposed hybrid algorithm, we briefly describe thesetwo algorithms first.

    After the identifiers of the sites in LRSK have been 2.2.1. Maekawas algorithmdetermined in each GroupK, the identifiers of the sites In Maekawas algorithm [ 2,7], a site S must exclu-in the global set Gs at site S can be determined. Note sively lock every site whose identifier is in its requestthat as far as a global algorithm (whose purpose is set before it executes the CS. In this algorithm, the re-

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    4/17

    718 Y.-l. Chang / Microprocessing and Microprogramming 41 (19961715-731

    quest set Rs of each site S has the following properties(whereN=K*(K-l)+landKEI+):(I) RsnRy##,S#Y,l

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    5/17

    Y.-I. Chang / Microprocessing and Microprogramming 41 (1996) 715-731 719

    2.2.3. Initialization of request sets in a hybridapproachIn a hybrid approach which uses Maekawas algo-rithm as the global algorithm and Singhals algorithmas the local algorithm, when N = 21 and g = 7 (i.e.,the number of sites per group = 3), the initializationof global and local sets is as follows:( 1) There are 7 groups in the system. According

    to the global algorithm (i.e., Maekawas algo-rithm), only one site identifier is needed in eachLRS for each group to mediate conflicts betweendifferent groups, as shown in Fig. la.

    (2) The identifiers of the sites in Gs are determinedaccording to the initialization of request sets inthe global algorithm. The global sets based onMaekawas algorithm are shown in Fig. lb.

    (3) The identifiers of the sites in LS are determinedaccording to the initialization of request sets inthe local algorithm. There are 3 sites in eachgroup and the local sets based on Singhals dy-namic information structure algorithm are shownin Fig. lc.

    (4) For each site, its request set is the union of itslocal and global sets.

    3. Design issuesIn a hybrid approach to mutual exclusion, two lev-

    els of mutual exclusion are required: local and global.Conditions of a CS entry in both local and global algo-rithms must be satisfied before a site can execute theCS (called the request phase). After a site finishes ex-ecution of the CS, appropriate actions should be takenbased upon exit codes in both algorithms (called therelease phase). The most difficult part in the design ofa hybrid algorithm is to control the interaction betweenthe local and global algorithms in these phases. Issuesin the design of a hybrid mutual-exclusion algorithmare modes of release, semantics of global messages,and modes of request.

    3.1. Modes of releaseAfter a site S finishes execution of the CS, it can re-

    lease global permission in many different ways (calledmodes of release). The modes of release can be lo-cal sites$rst or both local and global sites simultane-ously. In the release local si tes first mode, requestingsites in the same group as site S have a higher prior-ity in getting global permission than requesting sitesin the other groups. While in the release both globaland local sites simultaneously mode, every requestingsite has the same chance to get global permission.

    In the release local sit es first mode, a requestingsite Y in the same group as site S receives implicitglobal permission in an LReply message (i.e., a localreply) from site S. That is, site Y does not have to waitfor all GReply messages (i.e., global reply messages)for global permission. Therefore, message traffic andtime delay can be reduced for successive executionsof CS in the same group. In the release both local andglobal sites simultaneously mode, time delay betweensuccessive executions of CS is longer than the previ-ous mode. This is because a requesting site Y in thesame group as site S must wait for GReply messagesfrom sites whose identifiers are in Gr (= Gs), whichtakes one time delay for site S to release global per-mission and another time delay for sites whose identi-fiers are in Gr to send GReply messages to site Y (inMaekawas algorithm). Moreover, since site Y mustreceive a GReply message from every site whose iden-tifier is in Gr, more message traffic is generated in thismode than the previous mode.3.2. Semantics of global messages

    A global message is used to acquire global per-mission. The semantics of a GRequest message canbe a requesting site or a requesting group. The dif-ference in semantics can be expressed in differentforms of a GRequest message: GRequest(C,, S) orGRequest(Cs, S, K), which represents Site S is re-questing, or Site S in GroupK is requesting, respec-

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    6/17

    720 Y.-I. Chang / Mi croprocessing and Mi croprogramm ing 41 (1996) 715-731

    Group, = {1,2,3}Group* = {7,6}Group3 = {7,8,9}Group4 = {10,11,12}Groups = {13,14,15)Groups = {16,17,18}Group7 = {19,20,21}

    Group*, G = U LRS;, Vi E {1,2,3} - -> G, = G2 = G3 = {1,4,7}Groups, G = U LRSiy Vi E (2,4,6) - -> Gq = G5 = G6 = {4,10,16}Groups, G = U LRSi, Vi E {3,5,6} -> GT = Gs = Gg = {7,13,16}Groupd, G = U LRSi, Vi E {1,7} - -> G,o = GH = G12 = {1,10,13}Groups, G = U LRSi, Vi E {2,5,7} - -> G13 = G14 = G15 = {4,13,19}Groupe, G = U LRS;, Vi E {1,6,7} -> GM = G1, = GIs = (1,16,19)Group,, G = U LRSi, Vi E {3,4,7} -> GE, = G2o = Gz, = {7,lO,l9}

    Group1 Group2Ll = (1) L4 = (4)L2 = {L2) L5 = (7)L3 = {1,2,3I L6 = (776)Group4 GroupsLIO = (10) L13 = (13)L*1 = {lO,ll) L14 = {13,14}LIZ = {10,11,12} LlS = {13,14,15}

    LRSl = {l}LRSz = (4)LRS3 = (7)LRS4 = {IO)LRS5 = (13)LRScj = (16)LRS, = (19)

    (a)

    (b)Group3L7 = (7)L8 = {7,8}L9 = {7,8,9}Group6 Group7LN = (16) L9 = (19)LIT = {16,17} Lzo = {19,20}LIS = {16,17,18} Lzl = {19,20,21}

    Fig. I. Initialization. (a) LRS; (b) global sets; (c) local sets.tively.

    In the requesting group semantics, the same replymessages (granted or rejected) are sent to all request-ing sites in the same group (assuming that all request-ing sites in the same group have the same priority).In the requesting site semantics, different reply mes-sages can be sent to requesting sites in the same group(assuming that each requesting site in the same grouphas a different priority). In the requesting group se-mantics, several requesting sites in the same group cansimultaneously get global permission. While in the re-

    questing site semantics, a site must wait for the othersite in the same group to release global permission.Therefore, less time delay results in using the request-ing group semantics instead of the requesting site se-mantics.

    3.3. Modes of requestThe request phase of a hybrid mutual exclusion al-

    gorithm consists of the following four substeps:( 1) Send LRequest messages to all sites in Ls.

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    7/17

    Y.-I. Chang / Microprocessing and Mi croprogramm ing 41 (1996) 715-731 721

    (* for the local (Singhals) algorithm *)1,~ (as shown in Figure l-(c)): the local set (i.e. the request set in Singhals algorithm).LQs (= 4): the local queue (i.e., the inform set in Singhals algorithm).(* for the global (Maekawas) algorithm *)Gs (as shown in Figure l-(b)): the global set (i.e., the request set in Maekawas algorithm).GReplyCounts (= 0): the number of received GReply messages.GAskers (= 4): a set that records the identifiers of those sites which have sent GInquire messagesto site S.GFails (= 4): a set that records the identifiers of those sites which have sent GFailed messagesto site S.G&s (= 4): the global queue that records request(t, X) from site X with timestamp t.GLockSites (= 0): the site to which site S has granted its permission.GInqNos (= 0): the request timestamp of GLockSites.GSendInquires (= false): site S has sent a GInquire message to GLockSites.GNextQs (= 4): a set records the identifiers of those sites whose requests have a higher

    priority than all other requests received at site S so far.(* for controlling the interaction between the local and global algorithms *)LRequestings (= false): site S is requesting locally.GRequestings (= false): site S is requesting globally.LCS (= 0): the number of successive executions of CS in site Ss group.Globals (= false): site S has received all global permission.(* for both algorithms *)Executings (= false): site S is executing.Hs (= 0): the logic clock.CS (= 0): the timestamp with which site S invokes mutual exclusion.

    Fig. 2. Data structure and initialization in the hybrid algorithm.(2) Send GRequest messages to all sites in Gs.(3) Wait until the condition of the local algorithm is

    satisfied.(4) Wait until the condition of the global algorithm

    is satisfied.

    condition for mutual exclusion has been satisfied(called two-level request). Different modes of requestin conjunction with different semantics of global mes-sages and modes of release will yield different hybridalgorithms with varying properties.

    There are three possible sequences to execute When the requesting sequence 1234 in conjunctionthese steps in the request phase: 1234, 1324, and with the release local sitesfirst mode and the request-2413. In the requesting sequence 1234, LRequest and ing group semantics is used, every requesting site mustGRequest messages are sent out at the same time send GRequest messages for global permission even(called one-level request); whereas in the requesting though it can receive implicit global permission in ansequence 1324 (2413), LRequest (GRequest) mes- LReply message from the other site in the same group;sages are sent out first, then GRequest (LRcquest) therefore, some unnecessary global message traftic canmessages are sent out only after the local (global) be generated. Similarly, the requesting sequence 2413,

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    8/17

    722 Y.-I. Chang/ Microprocessing and Microprogramming 41 (1996) 715-731

    (* the request phase *)LRequestings = true;Cs = Hs + 1;Hs = Cs;if (Ls # 4) thenbegin

    send an LRequest(Cs, S) message to every site in Ls;wait until receive an LReply message from every site in Ls;(* i.e., wait until Ls = 4 *)

    endelse (* Ls = 4 *)beJ$

    t = LCs mod M;if (t > 0) then Globals = trueelse Globalc = false:

    end:LRequestings = false;GRequestings = true;if (not (Globals)) thenbegin

    GReplyCounts = 0;GAskers = GFails = 4;send a GRequest(Cs, S, K) message to every site in Gs;wait until receive a GReply message from every site in Gs;(* i.e., wait until GReplyCounts = [Gsl *)

    end;GReplyCounts = IGsl;GRequestings = false;Executings = true;

    Fig. 3. The request phase of the hybrid algorithm.where global competition is done before local compe-tition, has the same unnecessary global message traf-fic as the requesting sequence 1234 under the sameconsideration.In the requesting sequence 1324, local competitionoccurs before global competition. Thus, only one sitein a group sends GRequest messages to sites in theother groups for global permission even though severalsites in the same group are requesting. This requestingsequence, combined with the release local sites$rstmode and the requesting group semantics, can reducemore message traffic and time delay for successive

    executions of CS in the same group.Depending on the local and global algorithms used,

    some combination of the design issues may be infea-sible and some combinations will have better perfor-mance than others. In the next section, we present ahybrid mutual exclusion algorithm to demonstrate oneof the combinations of these design issues that leadsto better performance.

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    9/17

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    10/17

    724 Y.-I. Chang/ Microprocessing and Microprogramming 41 (1996) 715-731

    ables used to denote the state of site S, and they areset to true when site S is requesting locally or glob-ally, respectively. In order to avoid starvation result-ing from too many successive executions of CS in thesame group, a local counter LCS at site S keeps trackof the number of successive executions of CS in itsgroup. LCS is set to 0 initially and is increased by 1when site S finishes execution of the CS. This valueis passed around in an LReply message and is used asa flag: ( 1) the condition (LCs mod M) # 0, whereM is the upper bound of successive executions of CSin the same group, indicates implicit global permis-sion; (2) the condition (LCs mod M) = 0 indicatesthe absence of implicit global permission. When siteS releases global permission, LCS is increased by tsuch that ( (LCs + t) mod M) = 0, 0 < t < M.

    Globals denotes whether a requesting site S hasbeen granted all global permission. The initial valueof Globals is set to false, and it will be set to true inany of the following two cases: ( 1) when the request-ing site S has received a GReply message from everysite whose identifier is in Gs; (2) when the request-ing site S receives an LReply message in which theimplicit global permission exists. Moreover, each siteS maintains a logical clock Hs, which is updated ac-cording to Lamports rule [ 61. Every request for CSexecution is assigned a timestamp CS(= Hs + 1) toorder the requests.4.2. The algorithm

    In the algorithm, a site executes a request phase toinvoke mutual exclusion. After the site finishes execu-tion of the CS, it executes a release phase. Differentmessage handlers process incoming messages: LRe-quest, LReply, GRequest, GReply, GRelease, GFaiIed,GInquire, and GRelinquish.

    Fig. 3 shows the request phase of the hybrid al-gorithm, where the underlined statements are used tocontrol the interaction between the local and globalalgorithms. After site S has received all local permis-sion, it checks whether it has gotten implicit global

    p r o c e d u r e L R e q u e s t - H a n d l e r ;begin (* fo r LRequ es t (c , Y) m essage *)Hs = max{Hs, c};

    If (LRequestings) thenbegin

    if (Priority(S, Y)) then LQs = LQs U {Y}elsebegin

    send an LReply(Hs, S, LCs) message to site Y;if (not (Y E Ls)) thenbegin

    Ls = Ls u {Y};send an LRequest(Cs, S) message to site Y;

    end;end;

    endelse if ( (GReques t ings ) or (Executings)) then

    LQs = LQs u 0)elsebegin

    Ls = Ls u {Y};send an LReply(Hs, S, a) message to site Y;

    end;end;

    Fig. 5. LRequest Message Handler.permission by testing the value of t (= the remain-der of LCs/M). If t > 0, site S holds implicit globalpermission and sets Globals = true; otherwise, it setsGlobals = false. Depending on the value of Globals,site S decides whether it should acquire global per-mission explicitly.

    Fig. 4 gives the release phase of the hybrid algo-rithm. All global information is reset, Globals is setto false, and LCS is increased by 1. If LQs # 4, Supdates LS and LQ according to Singhals algorithm.Depending on the value of t (= the remainder ofLCs/M), the following two situations occur: ( 1) t >0: Site S sends its local permission with implicit globalpermission to sites whose identifiers are in LQs; (2)t = 0: In addition to sending its local permission withthe information about the absence of global permis-sion to sites whose identifiers are in LQs, site S alsoreleases global permission according to Maekawas al-gorithm. If there is no local request (LQs = $), siteS releases global permission according to Maekawas

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    11/17

    Y.-I. Chang/ Microprocessing and Microprogramming 41 (19%) 715-731

    p r o c e d u r e G R e q u e s t - H a n d l e r ;begin (* for GReq ue s t(c , Y, K) messa ge *)

    Hs = max{Hs, c};if (GLockSites # 0) thenbegin

    if ((Priority(GLockSites, Y)) or (P riority(Z, Y))) for any (t, Z) E GQs the]send a GFailed(Hs, S) message to site Yelsebegin

    if (not (GSendInquires)) thenbeginGSendInquires = true;send a GInquire(Hs, S, GInqNos) message to GLockSites;

    end;GNextQs = GNextQs U {Y}

    end;GQs = GQs u {Cc, Y));end

    else (* GLockSites = 0 *)beginGLockSites = Y;GInqNos = c;send a GReply(Hs, S) message to site Y;

    end;end;

    Fig. 6. GRequest Message Handler.

    725

    algorithm.In the LRequest Message Handler, shown in

    Fig. 5, site S decides whether it has to delay or grantits local permission according to Singhals algorithm.Every LReply message includes LCs as a flag ofthe existence of implicit global permission. In theGRequest Message Handler, shown in Fig. 6, siteS decides whether it has to reject this global request,or delay/grant its global permission according toMaekawas algorithm.

    In the LReply Message Handler, shown in Fig. 7,site S records local permission received according toSinghals algorithm and keeps updating the recentnumber of successive executions of CS in its groupbased on the information in the LReply message. Ifsite S has received all local permission, it decides

    whether it has implicit global permission by testingthe value of r (= the remainder of LCs/M). In theGReply Message Handler, shown in Fig. 8, siteS records global permission received according toMaekawas algorithm. If site S has received all globalpermission, it sets Globals = true.

    In the GRelease Message Handler, shown inFig. 9, site S resets its global information and sendsits global permission to the next requesting site (whenGQs # 4) according to Maekawas algorithm. Un-der the requesting group semantics, site S may receivea GRelease message from a site Y which is differentfrom GLockSites, but these two sites are in the samegroup. In the GFailed Message Handler, shown inFig. 10, site S relinquishes global permission to un-lock the sites which have sent GInquire messages to

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    12/17

    726 Y.-I. Chang/Microprocessing and Microprogramming 41 (1996) 715-731

    p r o c e d u r e L R e p l y - H a n d l e r ;beg in (* for LRep ly(c , Y, 9) m essa ge *)Hs = m ax {Hs, c};

    Ls = L s - {Y};LCs = m ax {LCs, LCy};if (Ls = I#) th enb e g i n

    t = LCs m od M;i f ( t > 0 ) th en Globa l s = t r ueelse Globa ls = fa lse ;

    end:e n d ;

    F ig . 7. LReply MessageH a n d l e r

    p r o c e d u r e G R e p l y - H a n d l e r ;beg in (* for GRep ly(c , Y) m essa ge *)

    Hs = m ax {Hs, c};GReplyCoun ts = GReplyCoun ts + 1 ;if (Y E GF ails ) th en GF ails = GFs& - {Y};i f (GRep1yCoun t . s = IGs l ) the n Globa l s = t rue ;

    F ig. 8 . GReply Message Handler.

    it (to break a possible circular wait) according toMaekawas algorithm.

    In the GInquire Messages Handler, shown inFig. 11, site S decides whether it should relinquishglobal permission to avoid possible deadlock accord-ing to Maekawas algorithm. If Cs # InquireNo, theGInquire message is a delayed old message and shouldbe ignored. If site S has received all global permis-sion, the GInquire message is ignored. If any of sitess global requests has been rejected, it relinquishesglobal permission to unlock site Y (to break a possi-ble circular wait) ; otherwise, site S adds the identifierof site Y to GAskers. In the GRelinquish MessageHandler, shown in Fig. 12, site S revokes its globalpermission to site Y and sends its global permission tothe other requesting site (to break a possible circularwait) according to Maekawas algorithm.

    p r o c e d u r e G R e l e a s e - H a n d l e r ;beg in (* for GRelea se(c , Y) m essa ge *)Hs = m ax {Hs, c};

    G S e n d I n q u i r e s = f a ls e ;i f (G&s # 4) th enbegin

    2 is the site in GQs with the highest priority;GLockSitec = Z:GInqNos = t, the request timestamp of site Z is t;G&s = GQs - {(t, Z));send a GReply(Hs, S) message to site Z;GNextQs = GNextQs - {Z};for every site W in GNextQs do

    send a Failed(Hs, S) message to site W;GNextQs = 4;

    endelse (* GQs = 4 *)begin

    GLockSites = 0;GInqNos = 0;

    end;end;Fig. 9. GRelease Message Handler.

    p r o c e d u r e G F a i l e d - H a n d l e r ;beg in (* for GFa iled(c , Y) m essa ge *)

    Hs = m ax {Hs, c};GF a i l s = GF a i l s U {Y};for every site Z in GAskers dobegin

    GAskers = GASkers - {Z);GFails = GFails u {Z);GReplyCounts = GReplyCounts - 1;send a GRelinquish(Hs, S) message to site Z;

    end;end;

    Fig. 10. GFa iled Message H a n d l e r .

    5. Corr ectness of the algorithmIn this section, we show that the proposed hybrid

    algorithm achieves mutual exclusion and is free fromdeadlock and starvation.

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    13/17

    Y.-l. Chang/ Microprocessing and Mi croprogramm ing 41 (1996) 715-731 121

    p r o c e d u r e G I n q u i r e - H a n d l e r ;begin (* fo r GInq u i r e (c , Y, Inqu i reNo) m e ssage *)

    Hs = max{Hs, c};if (C, = InquireNo) then

    if (GReplyCounts # \Gsl) thenbegin

    if (GFails # 4) thenbegin

    GFails = GFails u {Y};GReplyCounts = GReplyCounts - 1;send a GRelinquish(Hs, S) message to site Y;end

    else GAskers = GAskers U {Y};end;

    end;Fig. I 1. Glnquire Message Handler.

    p r o c e d u r e G R e l i n q u i s h - H a n d l e r ;begin (* fo r GRe l inqu i sh(c , Y) m e ssage *)

    Hs = max{Hs, c};2 is the site in GQs with the highest priority;GLockSites = Z;GInqNos = t, the request timestamp of site Z is t;GSendInquires = false;GQs = GQs - {(t,41;GQs =GQsu {c,Y);send a GReply(Hs, S) message to site Z;GNextQs = GNextQs - {Z};for every site W in GNextQs dosend a Failed(Hs, S) message to site W;GNextQs = 4;

    end;Fig. 12. GRelinquish Message Handler.

    5.1. Mutual exclusionTo prove that the algorithm achieves mutual exclu-

    sion, we have to show that two or more sites can neverbe executing the CS simultaneously; that is, one siteexits the CS before the next site enters the CS. Weshow that the algorithm achieves mutual exclusion bycontradiction.

    Assume that sites S and Y are executing the CS si-multaneously. If sites S and Y are in the same group,both sites must have received LReply messages fromall sites whose identifiers are in their local sets. How-

    ever, because of Singhals algorithm [ 151, this is im-possible. If sites S and Y are in different groups, bothsites must have received GReply messages from allsites whose identifiers are in their global sets. Be-cause of Maekawas algorithm [ 71, this is impossible.Therefore, two or more sites cannot execute the CS atthe same time.

    5.2. Freedom from deadlockA deadlock occurs when a set of sites are involved

    in a circular wait. Since the hybrid algorithm uses localcompetition followed by global competition, deadlockmay occur either among the sites in the same groupor among sites which are the winners of local compe-tition in different groups. That is, a deadlock cannotinvolve a mixture of sites in the local and global com-petition phases. Based on the proof of Singhals algo-rithm, it is impossible for deadlock to occur amongsites in the same group. For the second case, in whichdeadlock may occur among sites which are the win-ners of local competition in different groups, deadlockis avoided as in Maekawas algorithm by sending aGInquire message to require a locking site to yield ifits request has lower priority than any other request.Therefore, based on Maekawas algorithm, deadlockis avoided globally.

    5.3. Freedom from starvationStarvation occurs when some sites repeatedly ex-

    ecute the CS, while the other sites wait indefinitelyfor their turns to execute the CS. Since the hybridalgorithm uses local competition followed by globalcompetition, local starvation is impossible accordingto Singhals algorithm. Due to the release local sitesfirst mode, global starvation may occur as follows:There are several global requests from winners of localcompetition in different groups and some groups arerepeatedly getting global permission while the othergroups are waiting. In order to prove that starvation

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    14/17

    728 Y.-I. Chang/ Microprocessing and Mi croprogramm ing 41 (1996) 715-731will not occur globally, the following condition mustbe true:

    Condition. A group does not monopolize global per-mission. In other words, a group will release receivedglobal permission after a finite number of executionsof cs.Proof. Consider the following three cases which mayoccur after site S finishes execution of the CS (letts = LCs mod M) :( 1) There is no pending local request (LQs = 4) :

    Site S releases global permission and increasesLCsby(M--t)suchthat((LCs+t)modM)=0.(2) There are pending local requests (LQs # $) andIS > 0 after LCs has been increased by 1: SiteS sends its implicit global permission and localpermission to sites whose identifiers are in LQs.

    (3) There are pending local requests (LQs # 4)and ts = 0 after LCs has been increased by 1:Site S sends the information about the absenceof implicit global permission and its local per-mission to sites whose identifiers are in LQs, andreleases global permission.

    A site Y requesting the CS immediately after siteS (i.e., S E Lr) must receive an LReply (c, S, LCs)message from site S, and then updates LCr to themaximum value of (LCr, LCs). That is, LCr = LCs;therefore, ty = ts. If ty > 0, site Y gets implicit globalpermission and sets Globaly = true. If ty = 0, site Ysets Globaly = false and must acquire global permis-sion explicitly. Therefore, after at most M successiveexecutions of CS in a group, a site in this group will re-lease global permission. This implies that a group doesnot monopolize global permission. As in Maekawasalgorithms, global starvation will not occur in the hy-brid algorithm, where a group is regarded as a site inMaekawas algorithm.

    6. PerformanceThe performance of the hybrid algorithm was stud-

    ied using a simulation technique, and the performancemodel used in this paper is similar to the one used in[ 111. We assume that requests for the CS execution ar-rive at a site according to the Poisson distribution withparameter A. Message propagation delay between anytwo sites is constant (T) . The time taken by a site toexecute the CS is also constant (E) . A site processesthe requests for the CS one by one, and there is onlyone CS in the system. In this simulation study, thefollowing two performance measures are considered:( 1) Message Traffic: The average number of mes-

    sages exchanged among the sites per CS execu-tion.

    (2) Time Delay: The average time delay in grantingthe CS, which is the period of time between theinstant a site invokes mutual exclusion and theinstant when the site enters the CS.

    Simulation experiments were carried out for a ho-mogeneous system of N sites (N = 21 and N = 14) forvarious values of A (the arrival rate of CS requests),M (the upper bound of successive executions of CSin the same group), and g (the number of groups).Message propagation delay (T) between the sites wastaken as 0.1, and CS execution time (E) was takenas 0.01. The values of the parameters chosen here areconsistent with [ 111.

    Fig. 13 shows the message traffic as a function ofthe arrival rate. When N = 21 (and N = 14), g = 7and M = 3 (M = 2 in the case N = 14), message traf-fic in the hybrid algorithm can be reduced up to 52%(54% in the case N = 14) compared to Maekawas al-gorithm, and has much less message traffic than Sing-hals algorithm. This reduction results from the suc-cessive executions of CS in the same group and theuse of Maekawas algorithm among groups to reducemessage traffic. Moreover, for fixed N, message traf-fic decreases when g increases in the hybrid algo-rithm. The reason for this is that when g increases, thehybrid algorithm behaves more like the global algo-

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    15/17

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    16/17

    730 Y.-I. Chang/Mi croprocessing and Microprogramm ing 41 (1996) 715-731

    Arrival-Rote

    (4

    0, --

    0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 I .oArrival-Rate

    (b)Fig. 15. The percentage of successive executions of CS in thesame group: (a) N = 21; (b) N = 14.

    compared to Maekawas algorithm. The reason for thisreduction is that the hybrid algorithm uses Singhalsalgorithm within a group to reduce the long time delay.Fig. 15 shows the percentage of successive executionsof CS in the same group as a function of the arrival rate.

    We observe that up to 67% (50%) CS executions canimmediately enter the CS without requesting globalpermission explicitly, when N = 21 (and N = 14),g=7andM=3(M=2inthecaseN=14).

    7. ConclusionsIn this paper, we have proposed a hybrid approach

    to mutual exclusion to minimize both message trafficand time delay at the same time. In this approach, wehave divided a request set into a local set and a globalset which are used to enforce mutual exclusion locallyand globally and are initialized according to local andglobal algorithms, respectively. The most difficult partin the design of a hybrid mutual exclusion algorithm isto control the interaction between the local and globalalgorithms. The design issues include modes of re-lease, semantics of global messages and modes of re-quest. A hybrid mutual exclusion algorithm using therelease local sitesjrst mode, the requesting group se-mantics, and the requesting sequence 1324 (i.e., localcompetition followed by global competition) has beenfound to be an efficient way to control the interac-tion. We have presented a hybrid algorithm which usesSinghals dynamic information structure algorithm asthe local algorithm and Maekawas algorithm as theglobal algorithm. A simulation study reveals that theproposed hybrid algorithm can reduce message trafficby 52% and time delay by 29% at the same time ascompared to Maekawas algorithm. This reduction hasresulted from ( 1) the successive executions of CS inthe same group, (2) the use of Maekawas algorithmamong groups to reduce message traffic, and (3) theuse of Singhals dynamic information structure algo-rithm within a group to reduce long time delay.

    References[ 1 0.S.E Carvalho and G. Roucairol, On mutual exclu-

    sion in computer networks, Technical correspondence,Comm unicat ions ofA CM 26(2) (1983) 146-148.

  • 8/9/2019 Chang 1996 Micro Processing and Micro Programming

    17/17

    Y.-l. Chang / Microprocessing and Mi croprogramm ing 41 (1996) 715-731 731121 Y.1. Chang and M. Singhal, A correct O(a) distributedmutual exclusion algorithm, Proc. of th e 5th Int . Co@ o n

    Parallel and Disfributed Computing and Systems (October1992) 56-61.131 Y.1. Chang, Comments on two algorithms for mutualexclusion in real-time distributed computer systems, Journalof Parullel and D ist ribut ed Com put ing 23( 3) ( 1994) 449-4.54.[4 1 Y.I. Chang, Design of mutual exclusion algorithms for real-time distributed systems, Journal of Information Science andl$gineering lO(4) (1994) 527-528.J.M. Helary, A. Mostefaoui and M. Raynal, A general schemefor token- and tree-based distributed mutual exclusionalgorithm, IEEE Trans. on Parallel and Dist ributed Systems,S(2) (1994) 1185-1196.L. Lamport. Time, clocks and ordering of events indistributed systems, Communications of ACM 21(7) (1978)558-7.M. Maekawa, A fi algorithm for mutual exclusion indecentralized systems. ACM Trans. on Computer Sysfems3(2) (1985) 145-159.M. Naimi and M. Trehel, An improvement of the log(N)distributed algorithm for mutual exclusion, Proc. 7thInternat. Conf on Distributed Computing Systems (1987)371-375.(9 I S. Nishio, K.F. Li, and E.G. Manning, A resilient mutualexclusion algorithm for computer network, IEEE Trans. onParallel and Distribu ted Syst ems, I(3) ( 1990) 344-355.1 01 K. Raymond, A tree-based algorithm for distributed mutualexclusion, ACM Trans. on Computer Systems 7( 1) (1989)61-77.I 11 1 G. Ricart and A.K. Agrawala, Performance of a distributednetwork mutual exclusion algorithm, Tech. Rep. TR-774,Dept. Computer Science, Univ. of Maryland, College Park,MD, 1979.I 121 G. Ricart and A.K. Agrawala, An optimal algorithm formutual exclusion in computer networks, Comm. ACM 24( 1)(1981) 9-17.

    I131

    I141

    [I51

    L161

    [I71

    B.A. Sanders, The information structure of distributed mutualexclusion algorithms, ACM Trans. on Computer Systems5(3) (1987) 284-299.M. Singhal, A heuristically-aided algorithm for mutualexclusion in distributed systems, IEEE Trans. on Computers38(5) (1989) 651-662.M. Singhal, A dynamic information structure mutualexclusion algorithm for distributed systems, IEEE Trans. onParallel and Dist ribut ed Sys tem s 3( 1) (1992) 121-125.1. Suzuki and T. Kasami, A distributed mutual exclusionalgorithm, ACM Trans. on Com put er Syst ems 3(4) ( 1985)344-349.M. Trehel and M. Naimi, A distributed algorithm for mutualexclusion based on data structures and fault tolerance, JEERPhoenix Conf on Computer and Communications (1987)35-39.

    Ye-In Chang was born in Taipei, Tai-wan, in 1964. She received the B.S. de-gree in computer science and informa-tion engineering from The National Tai-wan University, Taipei, Taiwan, in 1986,and the M.S. and Ph.D. degrees in com-puter and information science from TheOhio State University, Columbus. OH,in 1987 and 1991, respectively.

    She joined the Department of Ap-plied Mathematics, National Sun Yat-SenUniversity, Kaohsiung, Taiwan, in 199 1,

    where she is now an associate professor. Her research interestsinclude database systems, distributed systems, knowledge-basedsystems and computer networks.