1 / 28

CIS 720

CIS 720. Message Passing. Message passing systems. Send statements Receive statements. Process naming. P ! m ( para_list ): send message m with parameters para_list to P. send(m( para_list , P)

awen
Download Presentation

CIS 720

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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: 1 + 2 + 6 • Reliable blocking send: 1 + 2 + 5 + 6 • Synchronous send: 1 + 2 + 3 + 4 + 5 + 6

  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: 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: 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: 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: do do i < n P2 ! A[i]; j < n  P1 ? B[j]; i = i + 1 j = j + 1 od od

  15. Satisfaction condition • one must show the following satisfaction condition for each pair of matching send and receive statements: P1 P2 : : {P}{Q} P2!expr P1?var {U}{V} : :

  16. P1: P2: y := 2 z := 1 P2 ! y P1 ? w P2 ? y P1 ! w + z

  17. P1: P2: {true} {true} 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}

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

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

  20. Example…. • P1: P2: v1 = 1; v2 = ? v3 = ?; v4 = 2 if if fi fi

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

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

  23. Computing the minimum value 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 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

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

  25. Centralized Semaphore • C: sem =1A: B: do do do sem =1; A ? p sem-- C!p; C!p [] cs cs sem=1; B ? p  sem-- C!v; C!v [] od od sem=0; A ? v  sem++ [] sem=0; B ? v  sem++ od

  26. Dining philosophers problem P0: do hungry acquire left and right fork eat release forks sleep od

  27. ! hungry

More Related