Consider the concurrent program consisting of the two processes shown below:
// Process 1 // Process 2 while(true) { while(true) { r1 = turn; r2 = turn; if (!r1) { if (r2) { <crit1>; <crit2>; turn = true; turn = false; } } } } // Shared datastructures boolean turn = r1 = r2 = false;
States are described by the following propositional variables:
The starting state is s0 = (¬t, ¬r1, ¬r2, ¬c1, ¬c2). Each process performs the following sequence of actions: copy the value of variable turn into its local variable r1 or r2; evaluate the if statement; depending on the outcome, either do its critical section and set turn to be true (false), or return to the first step. Actions can be arbitrarily interleaved. As usual we assume that assignment is an atomic operation. If we are in a state where for example r1 holds and t does not and process 1 executes atomic action r1 = turn we make a transition to a state where ¬r1 holds. In this example we can also assume that evaluating the if statement is an atomic operation since the value of the local variable can't be changed by another process. So if we are in the state where ¬r1 holds and process 1 evaluates the condition of its if statement, we move to a state where c1 is true.
Questions:
This file is maintained by Brian Logan Last modified: 2-Apr-2014, 09:26