Process synchronization using conditional critical region(CCR)


The concept of CS allow us to solve only mutual exclusion problems.
  So, it is generalized to solve other problems too (like producer, consumer)
  CCR is a CR with a provision for condition.
  await(B)   --->    instruction which lies inside CR.
  Structure of CR  ---> var :      x       :      shared


                             Region        x     do



Await(B)    --->   wait if B is false
Processes executing this and waiting will wait outside CCR. But, when they return to the instruction next to await.
Program process synchronization                                P2 wakes up P1
Var      x : shared
            wake: Boolean
Procedure process one
            Preliminary stuff one
            Region  x  do
            wake= false
            Other stuff one
Procedure process two
            Preliminary stuff two              (*) begin 
            Region  x  do                                      Wake= false 
            Begin                                                   Parbegin 
            Wake = true                                                    Process one 
            Await(wake)                                                   Process two 
            End                                                     Parend 
            Other stuff one                       end
If P1 is faster than P2, force it to wait. Otherwise allow P1 to continue


Case(i): P1 is faster than P2
Force P1 to wait. Bring it out of wait later 
initially wake = false
This means P1 wants to access x before P2 does. Since P2 is not holding x, P1 will be allowed to reach its CR.
It executes await instruction and waits as 
wake= false
P1 waits outside the CCR
x is not held up by P1
Later P2accesses x and reaches its CCR
wake = true is executed by P2
Since wake = true, P2 does not wait But P1 will be brought out of wait.
But, P1can not enter its CCR until x is released by P2.
This brings P1 out of wait.

Case(ii): P2  is faster than P1
i.e, P2 enters its CCR first.
This implies that P2 gets x and hence reaches its CCR.
P2 makes wake = true
When P2isin its CCR, ifP1  also tries, it is forced to wait.
Later P1 reaches its await instruction. It does not wait as wake = true.

Case (iii): P1 &P2  are equally  fast
Because of mutual exclusion on x only one of them reaches its CCR. The other waits.

Process synchronization is always achieved.


<< Prev | Next >>

Home | Notes Catalog | Privacy & Terms | About us | Contact us | Site map |     Copyright © 2016.                                     Template by