Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A. Frank - P. Weisberg
Cooperating Processes
Introduction to Cooperating Processes Producer/Consumer Problem The Critical-Section Problem Synchronization Hardware Semaphores
A. Frank - P. Weisberg
The critical section problem is to design a protocol that the processes can use so that their action will not depend on the order in which their execution is interleaved (possibly on many processors).
5
A. Frank - P. Weisberg
We can check on all three requirements in each proposed solution, even though the non-existence of each one of them is enough for an incorrect solution.
A. Frank - P. Weisberg
If only one process wants to enter, it should be able to. If two or more want to enter, one of them should succeed.
A. Frank - P. Weisberg
Hardware solutions
rely on some special machine instructions.
Software Solutions
We consider first the case of 2 processes:
Algorithm 1 and 2/3 are incorrect. Algorithm 4 is correct (Petersons algorithm).
Initial notation:
Only 2 processes, P0 and P1 When usually just presenting process Pi (Larry, I, i), Pj (Jim, J, j) always denotes other process (i != j).
11
A. Frank - P. Weisberg
Process Larry do { while (turn != Larry); critical section turn = Jim; remainder section } while (TRUE); Jims version is similar but Larry/Jim reversed.
13
A. Frank - P. Weisberg
14
do { while (turn != i); critical section turn = j; remainder section } while (TRUE); Satisfies mutual exclusion and bounded waiting, but not progress.
A. Frank - P. Weisberg
Process Larry
do { while (flag-jim); flag-larry = TRUE; critical section flag-larry = FALSE; remainder section } while (TRUE);
15
A. Frank - P. Weisberg
do { while (flag[j]); flag[i] = TRUE; critical section flag [i] = FALSE; remainder section } while (TRUE); Satisfies progress, but not mutual exclusion and bounded waiting requirements.
16
A. Frank - P. Weisberg
Process Larry
do { flag-larry = TRUE; while (flag-jim); critical section flag-larry = FALSE; remainder section } while (TRUE);
17
A. Frank - P. Weisberg
do { flag[i] = TRUE; while (flag[j]); critical section flag [i] = FALSE; remainder section } while (TRUE); Satisfies mutual exclusion, but not progress and bounded waiting (?) requirements.
18
A. Frank - P. Weisberg
20
21
Shared data: boolean choosing[n]; int number[n]; Data structures are initialized to FALSE and 0, respectively.
23
A. Frank - P. Weisberg
24
However, no valid solution can provide robustness against a process failing in its critical section (CS).
25
A process Pi that fails in its CS does not signal that fact to other processes: for them Pi is still in its CS.
A. Frank - P. Weisberg
Drawbacks of software solutions Software solutions are very delicate . Processes that are requesting to enter their critical section are busy waiting (consuming processor time needlessly).
If critical sections are long, it would be more efficient to block processes that are waiting.
26
A. Frank - P. Weisberg