1 - OS Process Synchronization
1 - OS Process Synchronization
Process P1 Process P2
1. x=5
2. x=5+2
1. read(x);
2. x=x+5;
3. printf( x);
Producer Consumer Problem
There can be two situations:
2. Bounderd Buffer:
1. Limited buffer size
Producer Consumer Problem
Bounderd Buffer:
Process P1 Process P2
1. reads i=10
2. i=i+1 =11
Remainder Section
} until false.
Solution to: Critical Section
1. Mutual Exclusion:
It states that if one process is executing in its critical section, then
no other process can execute in its critical section.
2. Bounded Wait:
It states that if a process makes a request to enter its critical
section and before that request is granted, there is a limit on
number of times other processes are allowed to enter that
critical section.
Solution to: Critical Section
3. Progress:
It states that process cannot stop other process from entering
their critical sections, if it is not executing in its CS.
i.e. Decision of entry into Critical Section is made by
processes in Entry Section By Setting Lock in Entry
Section
Software Solutions
Consider 2 Process Syatem
Algorithm 1.
b) if (shared variable == 2)
P2 can enter to Critical Section
2 Process S/w Approaches For C.S
Algo1:
Let shared variable is turn i.e. turn : 1 or 2
Pi:
while (turn != i)
{ do skip; }
Pi is in Critical Section;
turn=j;
do{
flag[i] = true; //Pi is ready to enter C.S
while (flag[j]); //Pi checks for Pj whether Pj is ready to
enter to C.S or not
Critical Section //Pi enters to C.S
flag[ i ]= false; Pi allows other processes to enter the C.S
Remainder Section
} while (1);
do {
flag[ i ] =true; // Pi is ready to enter C.S
turn=j;
while(flag[j] && turn ==j); // (flag and turn of Pj is True,
Until this condition is true, Pi can not enter C.S)
CRITICAL SECTION
flag[i]=false;
REMAINDER SECTION
}while(1);