Download presentation
Presentation is loading. Please wait.
1
CIS 720 Message Passing
2
Message passing systems
Send statements Receive statements
3
Process naming P ! m(para_list): send message m with parameters para_list to P. send(m(para_list, P) P ? m(para_list): receive message m from P, and assign the received parameters to variables in para_list. receive(m(para_list), P)
4
Channel naming send(m(para_list), ch) or ch!m(para_list)
receive(m(para_list), ch) or ch?m(para_list)
5
A: amount of synchronization and Buffering
6
Minimal synchronization: 1
Non-blocking send: 1 + 6 Blocking send: Reliable blocking send: Synchronous send:
7
Synchronous communication
Send statement: A ! m(expr): the send statement blocks until the receive statement is also enabled. Receive statement B ? m(var): the receive statement blocks until the send statement is also enabled. When matching send and receive statements are enabled, then var is assigned the value of expr
8
A pair of send and receive statements are matching if
The send statement appears in the process named in the receive statement. The receive statement appears in the process named in the send statement. var = expr is a valid assignment statement The type of the messages match
9
P1: P2: y := 2 z := 1 P2 ! y P1 ? w P2 ? y P1 ! w + z
10
P1: P2: P3: P3 ? y P3 ! w + z P1 ! x y := 2 z := 1 x = 1
P2 ! y P1 ? W P2 ? x P3 ? y P3 ! w + z P1 ! x
11
P1: P2: y := 2 z := 1 P2 ! y P1 ! w P2 ? y P1 ? w + z Deadlock
12
Array copying program A[0..N-1] B[0..N-1] i = 0; P1: P2: od od do do
i < n P2 ! A[i]; i < n P1 ? B[i] i = i + 1 od od
13
Array copying program A[0..N-1] B[0..N-1] i = 0; P1: P2: od od do do
i < n P2 ! A[i]; i < n P1 ? B[i] i = i + 1 od od This could deadlock because when i = n-1, P2 could check “i < n” before i is incremented.
14
Array copying program A[0..N-1] B[0..N-1] i = 0; j = 0 P1: P2: od od
do do i < n P2 ! A[i]; j < n P1 ? B[j]; i = i j = j + 1 od od
15
Satisfaction condition
one must show the following satisfaction condition for each pair of matching send and receive statements: P P2 : : {P} {Q} P2!expr P1?var {U} {V}
16
P1: P2: {true} {true} {w = 2} {z = 1 /\ w = 2} P2 ? y P1 ! w + z
y := 2 z := 1 {y = 2} {z = 1} P2 ! y P1 ? w {w = 2} {z = 1 /\ w = 2} P2 ? y P1 ! w + z {y = 3} {y = 3} { y = 2 /\ z = 1} w = y { w = 2 /\ z = 1} { w = 2 /\ z = 1} y = w + z { y = 3}
17
Guarded Communication
P ? x /\ bool action Guard evaluates to true if bool is true executing P ? x will not cause delay Guard evaluates to false if bool is false Guard blocks if bool is true but executing P ? x will cause delay
18
Mutual exclusion C: P1: P2: do do do P1?req P1?rel C!req; C!req
[] cs cs P2?req P2?rel C!rel; C!rel od od od
19
Example…. P1: P2: v1 = 1; v2 = ? v3 = ?; v4 = 2 if if fi fi
20
Example…. P1: P2: v1 = 1; v2 = ? v3 = ?; v4 = 2 if if
P2 ! v1 P2 ? v2 P1 ! v4 P1 ? v3 [] [] P2 ? v2 P2 ! v1 P1 ? v3 P1 ! v4 fi fi
21
Computing the minimum value
D: num=0; m = Max; A: B: C: do A ? v m = min(m,v);num D!a; D!b D!c [] D?a D?b D?c B ? v m = min(m,v);num++ [] C ? v m = min(m,v);num++ num = 3 A!m; B!m; C!m od
22
Computing the minimum value
A: a=initial value; num1 = 0 do B ? v a = min(a,v);num1++ [] C ? v a = min(a,v);num1++ B ! a skip; num1++ C ! a skip; num1++ num1 = 4 exit; od B: b=initial value; num2 = 0 do A ? v b = min(b,v);num2++ [] C ? v b = min(b,v);num2++ A ! a skip; num2++ C ! a skip; num2++ num2 = 4 exit; od
23
Centralized Semaphore
C: A: B: do do do A ? p A ? v C!p; C!p [] cs cs B ? p B ? v C!v; C!v od od od
24
Centralized Semaphore
C: sem =1 A: B: do do do sem > 0; A ? p sem C!p; C!p [] cs cs sem> 0; B ? p sem C!v; C!v [] od od sem=0; A ? v sem++ [] sem=0; B ? v sem++ od
25
Dining philosophers problem
do hungry acquire left and right fork eat release forks sleep od
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.