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

TMPA-2021: Fair Mutual Exclusion for N Processes

Exactpro
November 25, 2021

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

Exactpro

November 25, 2021
Tweet

More Decks by Exactpro

Other Decks in Technology

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. 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;
  4. 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
  5. 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
  6. 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
  7. 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?
  8. 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);
  9. 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);
  10. 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);
  11. 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);
  12. 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);
  13. 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);
  14. 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);
  15. 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
  16. 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
  17. 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
  18. 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;
  19. 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 ?
  20. 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 ?
  21. 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
  22. 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 ?
  23. Conclusion 30 • Open question: reduce the maximal waiting period

    • Open question: Peterson’s Algorithm in modern architectures