CIS 720
description
Transcript of CIS 720
![Page 1: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/1.jpg)
CIS 720
Asynchronous Message Passing
![Page 2: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/2.jpg)
Asynchronous message passing
• Send is non-blocking• Modeling a channel c:
1. Two variables: sentc, recvc
2. Queue
![Page 3: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/3.jpg)
Example
• P1:x = 0;send(x,ch1);receive(x,ch2);
P2:y = 2;
send(y,ch2); receive(y,ch1)
![Page 4: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/4.jpg)
Computing the minimum value
A: B: C:
a=initial value; m = Max; b = …. c = ….
B ! a; C !a; A!b; C!b A!c; B!c
B ? v; a = min(a,v); : :
C ? v; a = min(a,v);
![Page 5: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/5.jpg)
2-process mutual exclusion: Token passing
P0: sent = false; user_req = false; req_recd = false; hold = true do
!hold /\ user_req /\ !sent send(req,P1); sent = true; user_req = false;
[] receive(req,j) req_recd = true;
[] receive(token,x) hold = true; user_enter = true; [] user_release /\ req_recd send(token,P1); hold = false
req_recd = false; od
![Page 6: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/6.jpg)
Mutual exclusion: Token passingSite i:
sent = false; user_req = false; parent = initial_value; in_cs = false;
do
user_req if !sent then send(req,parent); sent = true;
enqueue <req,i> in Q; user_req = false;
[] receive(req,j) if
[] !hold if !sent then send(req,parent); sent = true;
enqueue <req,j> in Q;
[] hold && !in_cs send(token,j); parent = j; hold = false
[] hold && in_cs enqueue <req,j> in Q
fi
[] receive(token,x) hold = true;
if <req,i> in Q then in_cs = true;
else if j in Q then send(token,j); parent = j; hold = false
[] user_release in_cs = false; if j in Q then send(token,j); parent = j
od
![Page 7: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/7.jpg)
3
4
1 5 6
2
3
4
1 5 6
2
3
4
1 5 6
2
![Page 8: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/8.jpg)
![Page 9: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/9.jpg)
![Page 10: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/10.jpg)
• For each fork, use a request-based token protocol
• If request is from a higher id process then give up the fork.
• If request is from lower id process and you are hungry then delay sending the fork.
![Page 11: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/11.jpg)
12
3
45
f5
f4
f3
f2
f1
![Page 12: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/12.jpg)
12
3
45
f5
f4
f3
f2f1
Alternative strategy: Give up both forks at once
12
3
45
f5
f4
f3
f2f1
12
3
45
f5
f4
f3
f2f1
![Page 13: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/13.jpg)
![Page 14: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/14.jpg)
Drinking Philosophers problem
• Shared bottles• A philosopher may request a subset of
bottles
![Page 15: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/15.jpg)
Using dining philosophers…
• Each edge has a bottle and a fork• When a philosopher becomes thirsty, it
also becomes hungry• Request all neighboring forks• When all forks are received, requests the
desired bottles• As soon as the bottles are received,
release all the forks and start drinking
![Page 16: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/16.jpg)
Using sequence numbers
• Session_numi = current session number
• High_numi = highest session number received so far
![Page 17: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/17.jpg)
thirstyi for all bottles b needed, needb = true;
session_numi = high_numi + 1
tranquili for each consumed bottle b, needb = false;
if reqb then send b, holdb = false
needb /\ ! holdb /\ sentb send req(b,session_numi, i); sentb = false;
receive req(b,x,j) high_numi = max(x, high_numi); reqb = true;
if (! Needb \/ (Thirstyi /\ (session_numi, i) > (x,j)) then send b; holdb = false
![Page 18: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/18.jpg)
Committee Coordination Problem
• Each committee has a set of members• A professor may belong to more than one
committee• A meeting can be started only if all members are
available• No two committees with common members may
meet simultaneously• If all members of a committee are waiting then
some committee meeting must eventually take place
![Page 19: CIS 720](https://reader036.fdocuments.in/reader036/viewer/2022082712/56813cad550346895da6594f/html5/thumbnails/19.jpg)
• Committee = philosopher• Two committee share a fork if they have a common
member• Each professor is initially assigned a fixed number of
tokens, equal to the number of committees it belongs to• When a professor is willing to attend a committee
meeting, it sends a token to the corresponding philosopher.
• When a philosopher receives a token from every member, it changes status to hungry
• When it changes status to eating, meeting can be scheduled.