21
The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users. (U1,U2….,Un). Critical region:The user which has access to the resource is modelled as being in the critical region. Remainder region:When the user is not involved in anyway with the resource it is said to be in the remainder region. Trying Protocol:In order to gain admittance to its critical region the user executes a trying protocol. Exit Protocol: After the user is done with the resource it executes the exit protocol

The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Embed Size (px)

Citation preview

Page 1: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

The Problem

The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un).

Critical region:The user which has access to the resource is modelled as being in the critical region.

Remainder region:When the user is not involved in anyway with the resource it is said to be in the remainder region.

Trying Protocol:In order to gain admittance to its critical region the user executes a trying protocol.

Exit Protocol: After the user is done with the resource it executes the exit protocol

Page 2: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

The Cycle

• R

• T

• C

• E

• The try,crit,exit and rem actions are the only external actions of the shared memory.

Page 3: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Interactions Between Components for the mutual exclusion problem

criti

exiti

remi

tryi

Ui

1

ii

n

Page 4: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Well-Formedness: In any execution ,and for any i,the subsequence describing the interaction between Ui and A is well formed for Ui.

Mutual Exclusion:There is no reachable system state( a combination of a global state for A and states for all the Ui)in which more than one user is in the critical region C.

Progress:At any point in a fair execution,1)(Progress for trying region)If at least one user is in T and no other user is in C

then at some point later some user enters C.2)(progress for exit region)If atleast one user is in E,then at some later point some

user enters R.

Lockout- freedom(Lockout freedom for trying region)If all the users always return the resource thenany user that reaches T eventually enters C.(Lockout-freedom for exit region)Any user that reaches E eventually enters R.

Page 5: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Circulating Token Algorithm.

• The simplest mutual exclusion algorithm for the asynchronous send/receive network setting works when the network is a unidirectional ring.

• A token representing control of the resource circulates continously around the ring.

• When process Pi receives the token it checks whether or not there is an outstanding request from the user Ui.

• If there is no such request then Pi passes the token to Pi+1.

• If there is a request then Pi grants the resource to Ui and holds the token until Ui returns the resource.After that it passes token to Pi+1.

Theorem 20.1:- The CirculatingToken algorithm solves the mutual exclusion problem and guarantees Lockout-freedom.

Page 6: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

• Complexity Analysis:• Message complexity:-Messages are sent even when there are no active

requests,hence message complexity cannot be measured.So the total no of messages between tryi and the corresponding crit are considered to be at most n.When there is an active request at every node it is considered to be heavy load.

• Time complexity:- l is upper bound on time for each process task• d is upper bound for delay for oldest message in each

channel.• c is upper bound on the time any user spends in critical

region.• The time from Try event to the corresponding crit event is c(n-1)+dn+O(ln).• Virtual Rings:When used as arbitrary send/receive network based on strongly

connected directed graph G,consecutive processes on the ring need not be neighbours in G.

• Communication b/w any pair of processes can be simulated by a series of communications along a directed path in the underlying network .

• Fault Tolerance:When a process fails the other processes can reconfigure to form a new network.

• When a token is lost a new token can be generated using leader election protocol.

• Disadvantage:Ordinary process failures and message losses cannot be detected as processes cannot distinguish between failures from situations where there is a message delay.

Page 7: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

• LogicalTimeME algorithm:- Generates logical time pair (c,i).Algo uses both broadcast and send/receive between a pair of communicating processes.

• 1.Every process Pi maintains a single history data structure ex History(j) i records

• all msg Pi received from Pj along with a non negative clock value c.

• Try and exit requests are broadcast.

• 2.Every process acknowledges each try message with an ack message.

• 3.Pi can perform criti when its latest try request has reached its history(i) provided

• every try request previous to Pi’s request has been granted and Pi received a

• messages with greater logical time from every other process.

• Pi can perform a remi as soon as its exit request has reached its history(i).

• Theorem 20.2:The LogicalTimeME algorithm solves the mutual exclusion problem and guarantees lockout-freedom.

• Complexity Analysis:-• Message Complexity :-Try and exit messages lead to 2n individual

• messages added with (n -1) ack messages lead to 3n-1 messages on the whole.

• Time Complexity:- in case of strongly isolated request it is 2d + O(l) from Try to Crit.

Page 8: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

• RicartAgrawalaME algorithm algorithm eliminates the need for exit messages.Message complexity is only

2n-1 per request. The only message which is broadcast is try and the only message sent on the

send/receive channel is ok.Every message carried a clock value of its bcast or send event.

In response to a try message from Pj1.If Pi is in E,R or T ,before broadcasting the try message for its current request

Pi replies with ok.2.When Pi is in C it defers replying until it reaches E,and then immediately sends

its deferred oks.3.If Pi is in T and its current request has already been broadcasted then Pi

compares its own requests logical time (ti) with incoming try msg of Pj.If Ti>Tj then Pi’s request is given lower priority and it replies with ok

4.Pi can perform remi at any time after it recieves exiti

Theorem 20.3 RicartAgrawalaME algorithm solves the mutual exclusion problem and guarantees lockout freedom.

Page 9: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

General Resource Allocation.

The Problem

Consider the explicit resource for 4 users U1,U2,U3,U4 and the set R of resources

are(1),r(2),r(3),r(4) and the resource requirements of the 4 users are

U1:r(1),r(2) Conflicting pairs:-

U2:r(1),r(3) U1,U2

U3:r(2),r(4) U1,U3

U4:r(3),r(4) U2,U4

U3,U4

Explicit resource specification R for n users consists of

1.A universal finite set R of objects known as resources

2. For every I,1<=i<=n a set Ri belonging to R.

Exclusion specification(E) collection of bad sets of user indices….where bad set is a set of users that are not allowed to perform their work simultaneously.

Page 10: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Well Formedness :In any execution and for any i the subsequence

describing the interaction between Ui and A is well formed for Ui.

Exclusion:There is no reachable system state in which the set of users in

their critical regions is a set in E.

Progress : At any point in a fair execution

1.(Progress for trying region)If there is atleast one user in T and no user in

C then at some point later the user enters C.

2.(Progress for exit region)If there is atleast one user in E then at some

point later the user enters R.

Independent progress: At any point in a fair execution

1.(IP for trying region)If Ui is in T and all the conflicting users are in Ri then at some point either Ui enters C or some of the conflicting users enter T.

2.(IP for exit region)If Ui is in E and all the conflicting users are in R then at some point Ui enters R or some conflicting users enter T.

Page 11: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Coloring Algorithm.We include processes to manage each resource.Coloring of resource graph:-The resource allocation graph can be colored with two colors ,(ex:odd numbered resources by color 1 and even numbered by color 2),The colors are ordered in arbitrary ways to induce partial order to resource where r(i)<r(j) only if color of r(i) is ordered ahead of color of r(j).

SmallerResources appearAt the top.1.Each Pi simulates exactly one process of shared mem algo and some subset of resource processes2.When Ui wants to perform try(i )Pi collects the needed resources one at a time in increasing order of color,by sending msg to appropriate resource processes &waits for response..3.Each resource process adds the new request in their FIFO queue .When index i reaches the front of queue the resource process sends a msg back to Pi.4.Pi requests the next resource.5.When Pi recieves all the needed resources it performs crit(i ) and during exit (i) it sends a msg to all the involved resource processes so that they remove Pi’s index from their queue.

1 3

2 4 6

5

Page 12: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Time Bound depends on

1.Process step time

2.Msg delivery time

3.Critical region time

4.No of colors used to color the resource graph

5.Maximum no of users.

Page 13: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

RicartAgrawalaRA algorithm.

Processes compute logical times using LamportTime algorithm.

After a try(i) process i multicasts a try msg with an associated clock value to all the

processes with which it shares resources.Process i can go to C after it recieves

subsequent OK messages from all these processes.

Same rules apply for sending OK messages as in RA’s ME algorithm.

Process i can perform rem(i) at any time after it recieves exit(i).

Theorem:The RicartAgrawalaRA algorithm solves the general resource allocation

problem for a given resource specification and guarantees lockout freedom and

independent progress.

Page 14: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Acyclic Diagraph Algorithm:Explicit resource specification:-

1.Each resource is in the resource set of exactly 2 users.

2.Each pair of users share at most one resource.

Orientation of edges in G are maintained in such a way that at a time the diagraph H

Consists of all orientations which are acyclic.

If process i is in the trying region and has its incident edges oriented inward then it

can perform crit(i) operation.

If in the exit region then it can perform rem(i) and set all its orientation edges to

point outward and send a change message on each incident edge all in one step.

If process i is in the remainder region with all its edges oriented inward then process

i can set all its orientation variables to point outwards and send a change message on

each incident edge again in one step.

i j i j

Page 15: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Theorem 20.5

The AcyclicDiagraphRA algorithm solves the resource allocation problem and

guarantees lockout freedom:

Processes P4 and P6 are in crit at the same time.1 2

3 4

7

5

6

21

3 4

21

3 4

21

3 4

21

3 4

Page 16: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Drinking Philosophers

General resource allocationmodule

UiUj

Di

Dj

Page 17: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

A variant of general resource allocation problem allows the user to request different

resources at different times.

Resources are sometimes called bottles.

The communication b/w each Di and general resource allocation algo uses

Internal try,internal crit,internal rem,internal exit actions.

Page 18: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

ModularDP algorithm.When Di recieves Try(B)i it sends requests for those bottles that is needs but currently lacks.Recipient Dj of a request satisfies it if Uj is in E or R,If Uj is in T or C then Dj defers the request so that it can satisfy it when Uj finishes the critical region.So to prevent 2 processes from deferring each others requests and thus blocking progress a general resource allocation module is used to establish

priority between the processes.1.When Di is in the trying region it invokes internal try( i) to try and gain priority.2.When Di recieves the internal Crit(i) input while its still in the trying region it enters the internal critical region.-it sends demand message for the bottles that are still missing. 3.The recipient Dj of demand always satisfies it if it has the bottle and is not in the critical region using the bottle. 4.Once Di enters the internal critical region it recieves all the bottles it needs and then from its trying region it enters the critical region. 5.Once Di enters the critical region it can output internal exit(i) since it no longer needs the priority associated with the internal critical region.

Page 19: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

Theorem 20.6

The ModularDP algorithm using any lockout free solution to the

general resource allocation problem solves the drinking philosophers problem and

guarantees lockout freedom.

Theorem 20.7

In any fair execution of the ModularDP system if every crit is followed

by a corresponding exit then every internal crit is followed by a corresponding

internal exit.

Theorem 20.8

In any fair execution of the ModularDP system if every crit is followed by a

Corresponding exit then every try is followed by a corresponding crit.

Page 20: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The

End of slides

Page 21: The Problem The Mutual exclusion problem involves the allocation of a single indivisible,nonshareable resource among n users.(U1,U2….,Un). Critical region:The