Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TMPA-2021: Fair Mutual Exclusion for N Processes

TMPA-2021: Fair Mutual Exclusion for N Processes

Yousra Hafidi, Jeroen J.A. Keiren and Jan Friso Groote, Eindhoven University of Technology

Fair Mutual Exclusion for N Processes

TMPA is an annual International Conference on Software Testing, Machine Learning and Complex Process Analysis. The conference will focus on the application of modern methods of data science to the analysis of software quality.

To learn more about Exactpro, visit our website https://exactpro.com/

Follow us on
LinkedIn https://www.linkedin.com/company/exactpro-systems-llc
Twitter https://twitter.com/exactpro

5206c19df417b8876825b5561344c1a0?s=128

Exactpro
PRO

November 25, 2021
Tweet

Transcript

  1. Fair Mutual Exclusion for N Processes Presented by Yousra Hafidi

    TMPA, 25 November 2021 Yousra Hafidi, Jeroen J. A. Keiren, and Jan Friso Groote Eindhoven University of Technology, Eindhoven, The Netherlands Department of Mathematics and Computer Science, Formal System Analysis Group {y.hafidi, j.j.a.keiren, j.f.groote}@tue.nl FORMAL SYSTEM ANALYSIS RESEARCH GROUP
  2. Mutual Exclusion Problem 2 CS Process 1 Process 0 Max

    one process Peterson’s original algorithm for two processes Peterson’s generalized algorithm for N>2 processes : filter-lock version Peterson’s generalized algorithm for N>2 processes : tournament tree version
  3. 1. Peterson’s Algorithm for N=2 Processes

  4. Peterson’s algorithm for N=2 processes 4 Process 0 Process 1

    1. flag[0] = True; 2. wait = 0; 3. while (flag[1] and wait == 0) do {} 4. CS 5. flag[0]=false; 1. flag[1] = True; 2. wait = 1; 3. while (flag[0] and wait == 1) do {} 4. CS 5. flag[1]=false; flag[2] : Boolean; Indicates if the process requests access to the CS. wait : int; Indicates that the process is waiting for the other one;
  5. Peterson’s algorithm for N=2 processes 5 Mutual Exclusion Starvation Freedom

    Bounded overtaking Requirements ? Only one  Satisfied (B = 2)  Satisfied  Satisfied Eventual access Overtaken B times
  6. 2. Peterson’s Algorithm for N>2 Processes (Tournament tree)

  7. Peterson’s Algorithm for N>2 Processes 7 Level 0 Level 1

    i = 1 i = 2 i = 0 i = 4 Level 2 4 5 6 i = 3 i = 5 i = 6 i = 7 Side = 0; Left side Side = 1; Right side Leaves Internal nodes Root Candidates 3 0 1 2 Progress Contestants of node 3 Contestants of node 4 Contestants of node 5 Contestants of node 6 Tournament tree
  8. Peterson’s Algorithm for N>2 Processes 8 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖_𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑛𝑁𝑁 𝑖𝑖 = 2𝐾𝐾

    − 1 + 𝑖𝑖 2 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖_𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑁𝑁 𝑖𝑖 = 𝑖𝑖 𝑚𝑚𝑚𝑚𝑚𝑚 2 𝑝𝑝 𝑛𝑛 = 𝑛𝑛 2 − 1 • K : the number of levels; • N : the total number of contestants; • 𝑛𝑛 : a node id; • 𝑖𝑖 : a process id; i = 1 i = 2 CS i = 0 Level 0 Level 1 1 2 0
  9. Peterson’s Algorithm for N>2 Processes 9 Variables: Flag wait i

    = 1 i = 2 CS i = 0 Level 0 Level 1 1 2 0 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔1 0 = 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔2 0 = 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 = 1 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡0 = 0 Formal model?
  10. Peterson’s Algorithm for N>2 Processes 10 mCRL2 specification act enter,

    leave: Nat; Process id act get_flag_s, get_flag_r, get_flag, set_flag_s, set_flag_r, set_flag: Nat # Nat # Bool; node side Is set ? proc Flag(node: Nat, side: Nat, v: Bool)= sum v': Bool. set_flag_r(node, side, v'). Flag(node, side, v') + get_flag_s(node, side, v). Flag(node, side, v);
  11. Peterson’s Algorithm for N>2 Processes 11 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  12. Peterson’s Algorithm for N>2 Processes 12 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  13. Peterson’s Algorithm for N>2 Processes 13 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  14. Peterson’s Algorithm for N>2 Processes 14 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  15. Peterson’s Algorithm for N>2 Processes 15 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  16. Peterson’s Algorithm for N>2 Processes 16 mCRL2 specification Proc Peterson(id:

    Nat, node: Nat, side: Nat) = set_flag_s(node, side, true). set_wait_s(node, side). (get_flag_r(node, other(side), false) + get_wait_r(node, other(side))). ((node == 0) -> enter(id). leave(id) <> Peterson(id, Int2Nat(ceil(node/2) - 1), (node+1) mod 2)). set_flag_s(node, side, false);
  17. Peterson’s Algorithm for N>2 Processes 17 Mutual Exclusion: At any

    time, at most one process can be in the critical section. MCF: TRUE
  18. Peterson’s Algorithm for N>2 Processes 18 Starvation freedom: If a

    process requests access to its critical section, then, it will be able to have it in a finite number of steps. MCF: False
  19. Peterson’s Algorithm for N>2 Processes 19 Starvation freedom: Counterexample Process

    0 Process 1 Process 2
  20. Peterson’s Algorithm for N>2 Processes 20 i = 0 𝑓𝑓lag1

    0 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 ≔ 0; 𝑓𝑓lag1 1 = false; 𝑓𝑓lag2 [0] ≔ true; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡2 := 0; 𝑓𝑓lag2 1 = 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; 𝑓𝑓lag0 [1] :=true; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡0 := 1; 𝑓𝑓lag0 0 = 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; Enter the CS Leave the CS 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔0 1 ≔ 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔2 0 ≔ 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; 𝑓𝑓lag1 1 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 ≔ 1; i = 1 i = 2 i = 1 i = 2 CS i = 0 Level 0 Level 1 1 2 0
  21. Peterson’s Algorithm for N>2 Processes 21 i = 0 𝑓𝑓lag1

    0 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 ≔ 0; 𝑓𝑓lag1 1 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 ≔ 1; i = 1 i = 1 i = 2 CS i = 0 Level 0 Level 1 1 2 0 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 == 1; 𝑓𝑓lag0 0 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡0 : = 0; 𝑓𝑓lag0 0 == 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; Enter the CS Leave the CS 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔0 0 ≔ 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; 𝑓𝑓𝑓𝑓𝑓𝑓𝑔𝑔1 0 ≔ 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; 𝑓𝑓lag1 0 ≔ 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡; 𝑤𝑤𝑤𝑤𝑤𝑤𝑡𝑡1 ≔ 0;
  22. Peterson’s Algorithm for N>2 Processes 22 i = 1 i

    = 2 CS i = 0 Level 0 Level 1 1 2 0 How to consider the individual progress of processes that are not attached to a same node ?
  23. 3. Fair mutual exclusion algorithm for N>2 processes

  24. Fair mutual exclusion algorithm for N>2 processes 24 i =

    1 i = 2 CS i = 0 Level 0 Level 1 1 2 0 next3 (0, 2) = 1 next3 (1, 2) = 0 𝑓𝑓laginit_no𝑑𝑑𝑑𝑑(𝑛𝑛𝑛𝑛𝑛𝑛𝑡𝑡𝑁𝑁 𝑡𝑡,𝑖𝑖 ) init_side(𝑛𝑛𝑛𝑛𝑛𝑛𝑡𝑡𝑁𝑁 𝑡𝑡, 𝑖𝑖 ) = 𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓𝑓; next3 (0, 0) = 2 next3 (1, 1) = 2 next3 (0, 0) = 2 next3 (1, 1) = 2 requests access to CS or not ?
  25. Fair mutual exclusion algorithm for N>2 processes 25

  26. Fair mutual exclusion algorithm for N>2 processes 26 Mutual Exclusion:

    At any time, at most one process can be in the critical section.  TRUE Starvation freedom: If a process requests access to the critical section, then, it will be able to have it in a finite number of steps.  TRUE Bounded-overtaking: There is a bound B on the number of times a process can be overtaken by other processes once it has requested access to its critical section MCF:  TRUE
  27. Fair mutual exclusion algorithm for N>2 processes 27 Verification results

    for the fair mutual exclusion algorithm for N processes. Verification results for Peterson's algorithm for N processes Ubuntu Server 18.04 LTS with 4 x Intel(R) Xeon(R) Gold 6136 CPU @ 3.00GHz (96 processors) and 3TB of RAM. Single processor core. Timeout of 4 hours. Bound for 𝑵𝑵 ≥ 𝟓𝟓 processes ?
  28. 5. Conclusion

  29. Conclusion 29

  30. Conclusion 30 • Open question: reduce the maximal waiting period

    • Open question: Peterson’s Algorithm in modern architectures
  31. Thank You For Your Attendance Questions ? Yousra Hafidi Mail:

    y.hafidi@tue.nl