Modeling and Analysis of Dekker-Based Mutual Exclusion Algorithms
Abstract
:1. Introduction
2. Background
2.1. The Concepts of a Mutual Exclusion Algorithm
Algorithm 1. The pseudo-code of a mutual exclusion algorithm. |
shared communication variables Process(i) local variables repeat NCS; Entry-part; CS; Exit-part; forever |
- (a)
- The absence of a deadlock: The protocol execution must not determine a fatal reciprocal lockout of the processes in any cases in which no one can prosecute. In a deadlocked state, every process awaits someone to do something that never occurs.
- (b)
- Only one process can execute its CS at a time (the essence of mutual exclusion).
- (c)
- The absence of individual starvation: No competing process, that is, the one executing the Entry-part of the protocol, should wait for an unbounded time before entering its CS.
- (d)
- A process in the NCS should not impede another process from entering its CS.
- (e)
- No hypothesis should be made on the relative speed of processes.
2.2. Memory Model Constraints
2.3. Modeling Language
3. Modeling and Verification Approach
- (a)
- Each process is an instance of a basic Process (const pid i) parameterized automaton, where pid is the type of the process identifiers and i is the unique id of the process instance.
- (b)
- Elementary actions in the Entry/Exit parts (see Algorithm 1) are assumed to consume no time and are modeled by commands exiting from urgent locations.
- (c)
- Busy-waiting actions in the Entry/Exit parts are mapped onto normal locations from which the exit is commanded as soon as the busy-waiting condition ceases to hold. To force an immediate exit from the busy-waiting location, an urgent and broadcast channel () is used, whose signal is sent, but it is not received by any other process.
- (d)
- The non-critical section (NCS in Algorithm 1) is represented by a normal location with a spontaneous exit (i.e., with a void guarded command). This way, the NCS can be abandoned after an arbitrary dwell time. An infinite dwell time models the process that stops being executed and will no longer compete to access the shared resource.
- (e)
- The critical section (CS in Algorithm 1) is expressed by a normal location, which is abandoned after exactly one time unit has elapsed. Time-sensitive behavior is achieved by associating one clock per process instance, which is reset at the entrance to the CS. The invariant of the CS location is x[i] <= 1, and the guard for exiting CS is x[i] >= 1.
- (f)
- The repeat-forever loop of Algorithm 1 is achieved by re-entering the NCS location after exiting the CS location. Before entering the NCS, all the Exit-part actions must be executed.
- bool flag[N]; //all false initially by default;
- pid turn; //initial value is immaterial.
Algorithm 2. Pseudo-code for Dekker’s mutual exclusion for two processes. |
Process(i): local pid j = 3−i; //partner process repeat NCS //Entry-part flag[i] = true; while(flag[j]){ if(turn == j){ flag[i] = false; await(turn ! = j); //busy-waiting/spin-lock flag[i] = true; } } CS //Exit-part turn = j; flag[i] = false; forever |
- const int N = 2;
- typedef int[1,N] pid;
- bool flag[pid]; //all false initially by default;
- pid turn; //default initialization;
- urgent broadcast chan synch;
- clock x[pid]; //one clock per process instance.
- const pid tp = 1; //target process;
- void reset(const pid i){;
- if(i == tp) x[tp] = 0;
- }//reset.
Checking the Dekker’s Solution on a Weak Memory
4. Analysis of Dekker’s Variants
4.1. Doran and Thomas’s Variant
Algorithm 3. The Doran and Thomas variant of the Dekker’s algorithm. |
Process(i): local pid j = 3−i; //partner process repeat NCS //Entry-part flag[i] = true; if(flag[j]){ if(turn ! = i){ flag[i] = false; await(turn == i); //1st busy-waiting flag[i] = true; } await(!flag[j]); //2nd busy-waiting } CS //Exit-part turn = j; flag[i] = false; forever |
- E<> Process(tp).BW2 && x[tp] == 2
4.2. Buhr, Dice, and Hesselink’s Variant
Algorithm 4. The Buhr, Dice, and Hesselink variant of Dekker’s algorithm. |
Process(i): local pid j = 3−i; //partner process repeat NCS repeat //Entry-part flag[i] = true; if(!flag[j]) break; if(turn == i){ await(!flag[j]); //1st busy-waiting break; } flag[i] = false; await turn == i); //2nd busy-waiting forever CS //Exit-part turn = j; flag[i] = false; forever |
5. Embedding Algorithms in a Tournament Tree
5.1. Tournament Tree Based on Dekker’s Algorithm
5.2. Tournament Tree Based on Doran and Thomas Variant Algorithm
5.3. Tournament Tree Based on Buhr, Dice, and Hesselink Variant Algorithm
6. Summary of the Results
7. Conclusions
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Lamport, L. The mutual exclusion problem: Part I—A theory of interprocess communication. In Concurrency: The Works of Leslie Lamport; Association for Computing Machinery: New York, NY, USA, 2019; pp. 227–245. [Google Scholar]
- Lamport, L. The mutual exclusion problem: Part II—Statement and solutions. In Concurrency: The Works of Leslie Lamport; Association for Computing Machinery: New York, NY, USA, 2019; pp. 247–276. [Google Scholar]
- Misra, J. A Discipline of Multiprogramming; Springer: Berlin/Heidelberg, Germany, 2001. [Google Scholar]
- Raynal, M. Concurrent Programming: Algorithms, Principles, and Foundations; Science & Business Media: Berlin/Heidelberg, Germany, 2012. [Google Scholar]
- Silbershatz, A.; Galvin, P.B.; Gagne, G. Operating System Concepts, 10th ed.; Wiley: Hoboken, NJ, USA, 2018. [Google Scholar]
- Goetz, B. Java Concurrency in Practice; Pearson Education: Singapore, 2006. [Google Scholar]
- Aravind, A.A.; Hesselink, W.H. A queue based mutual exclusion algorithm. Acta Inform. 2009, 46, 73–86. [Google Scholar] [CrossRef]
- Clarke, E.M.; Grumberg, O.; Peled, D.A. Model Checking; MIT Press: Cambridge, MA, USA, 2000. [Google Scholar]
- Behrmann, G.; David, A.; Larsen, K.G. A tutorial on UPPAAL. In Formal Methods for the Design of Real-Time Systems; Bernardo, M., Corradini, F., Eds.; LNCS 3185; Springer: Berlin/Heidelberg, Germany, 2004; pp. 200–236. [Google Scholar]
- Alur, R.; Dill, D.L. A theory of timed automata. Theor. Comput. Sci. 1994, 126, 183–235. [Google Scholar] [CrossRef]
- Buhr, P.A.; Dice, D.; Hesselink, W.H. High-performance N-thread software solutions for mutual exclusion. Concurr. Comput. Pract. Exp. 2014, 27, 651–701. [Google Scholar] [CrossRef]
- Buhr, P.A.; Dice, D.; Hesselink, W.H. Dekker’s mutual exclusion algorithm made RW-safe. Concurr. Comput. Pract. Exp. 2016, 28, 144–165. [Google Scholar] [CrossRef]
- Frenzel, L.E. Dual-port SRAM accelerates smart-phone development. In Electronic Design; Endeavor Business Media LLC: Nashville, TN, USA, 2004. [Google Scholar]
- Wang, Z.; Zuo, Q.; Li, J. An intelligent multi-port memory. In International Symposium on Intelligent Information Technology Application Workshops; IEEE: Piscataway, NJ, USA, 2008; pp. 251–254. [Google Scholar]
- Dijkstra, E.W. Co-operating sequential processes. In Programming Languages; Genuys, F., Ed.; NATO Advanced Study Institute, Academic Press: London, UK; New York, NY, USA, 1968; pp. 43–112, Also EWD123 1965. [Google Scholar]
- Doran, R.W.; Thomas, L.K. Variants of the software solution to mutual exclusion. Inf. Process. Lett. 1980, 10, 206–208. [Google Scholar] [CrossRef]
- Peterson, G.L.; Fischer, M.J. Economical solutions for the critical section problem in a distributed system. In Proceedings of the Ninth Annual ACM Symposium on Theory of Computing, El Paso, TX, USA, 4–6 May 1977; pp. 91–97. [Google Scholar]
- Kessels, D.E. Arbitration without common modifiable variables. Acta Inform. 1982, 17, 135–141. [Google Scholar] [CrossRef]
- Hesselink, W.H. Tournaments for mutual exclusion: Verification and concurrent complexity. Form. Asp. Comput. 2017, 29, 833–852. [Google Scholar] [CrossRef]
- Murata, T. Petri nets: Properties, analysis and applications. Proc. IEEE 1989, 77, 541–580. [Google Scholar] [CrossRef]
- Nigro, L.; Cicirelli, F. Formal modeling and verification of embedded real-time systems: An approach and practical tool based on Constraint Time Petri Nets. Mathematics 2024, 12, 812. [Google Scholar] [CrossRef]
- Cicirelli, F.; Furfaro, A.; Nigro, L. Model checking time-dependent system specifications using time stream Petri nets and Uppaal. Appl. Math. Comput. 2012, 218, 8160–8186. [Google Scholar] [CrossRef]
- Bowman, H.; Gomez, R.; Su, L. A tool for the syntactic detection of zeno-timelocks in Timed Automata. Electron. Notes Theor. Comput. Sci. 2005, 139, 25–47. [Google Scholar] [CrossRef]
- Peterson, G.L. Myths about the mutual exclusion problem. Inf. Process. Lett. 1981, 12, 115–116. [Google Scholar] [CrossRef]
- Knuth, D.E. Additional comments on a problem in concurrent programming control. Commun. ACM 1966, 9, 321–322. [Google Scholar] [CrossRef]
- Nigro, L. Parallel Theatre: An actor framework in Java for high performance computing. Simul. Model. Pract. Theory 2021, 106, 102189. [Google Scholar] [CrossRef]
# | Query | Result |
---|---|---|
1 | A[] !deadlock | satisfied |
2 | A[] (sum(i:pid)Process(i).CS)<=1 | satisfied |
3 | E<> Process(1).CS | satisfied |
4 | E<> Process(2).CS | satisfied |
5 | E<> Process(1).NCS && Process(2).CS | satisfied |
6 | Process(1).C --> Process(1).CS | not satisfied |
7 | Process(1).BW --> Process(1).CS | not satisfied |
8 | sup{ Process(tp).C }: x[tp] | 1 |
N | ov |
---|---|
2 | 1 |
3 | 3 |
4 | 3 |
5 | 7 |
6 | 7 |
7 | 7 |
8 | 7 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Nigro, L.; Cicirelli, F.; Pupo, F. Modeling and Analysis of Dekker-Based Mutual Exclusion Algorithms. Computers 2024, 13, 133. https://doi.org/10.3390/computers13060133
Nigro L, Cicirelli F, Pupo F. Modeling and Analysis of Dekker-Based Mutual Exclusion Algorithms. Computers. 2024; 13(6):133. https://doi.org/10.3390/computers13060133
Chicago/Turabian StyleNigro, Libero, Franco Cicirelli, and Francesco Pupo. 2024. "Modeling and Analysis of Dekker-Based Mutual Exclusion Algorithms" Computers 13, no. 6: 133. https://doi.org/10.3390/computers13060133