Process Synchronization
Process Synchronization
A. Frank - P. Weisberg
2. Progress – If no process is executing in its critical
section and there exist some processes that wish
to enter their critical section, then the selection
of the process that will enter the critical section
next cannot be postponed indefinitely:
A. Frank - P. Weisberg
3. Bounded Waiting – A bound must exist on the
number of times that other processes are allowed
to enter their critical sections after a process has
made a request to enter its critical section and
before that request is granted.
A. Frank - P. Weisberg
2 process pi & pj
Alg 1:
Both share a common variable turn=i or j.
If turn ==i process Pi allowed to execute in
critical section.
Do
{
while(turn !=i)
Critical section;
Turn =j;
Remainder section;
}while(1);
Drawback: does not satisfy progress
requirements(state of process). Only
remembers about process which was allowed
to enter in its critical section.
Prob 1 solved by replacing variable turn with
boolean = flag[2].
Element of array initialized to false. If flag[i]
=true, value indicates pi ready to execute in
its critical section.
Structure of process pi
Do
{
flag[i]=true ;
While(flag[i])
Critical section;
flag[i]=false;
Remainder section;
}while(1);
Combine alg1 and alg2. process shares 2
variables: Boolean flag[2], int turn.
Initially flag[0] = flag[1]=false & value of
turn is immaterial(0 or 1).
Do
{
flag[i]=true ;
turn = j;
While(flag[i] && turn ==j)
Critical section;
flag[i]=false;
Remainder section;
}while(1);