does my solution satisfy the requirements for a mutual exclusion

260 views Asked by At

i wrote 2 processes in order to satisfy mutual exclusion but om not sure if it is.. my initial flag value is 0.

process 1
while(1){

while flag=1 do{-nothing-}

flag=1

-enter critical section-

flag=0

}

process 2
while(1){

while flag=1 do{-nothing-}

flag=1

-enter critical section-

flag=0

}

in fact they are exactly the same. does those 2 processes satisfy the mutual exclusion? i cant see what requirement is violated..

1

There are 1 answers

0
ajuc On BEST ANSWER
Process 1                            Process 2

check if flag is 0 - it is
                                          check if flag is 0 - it is
set flag to 1
                                          set flag to 1        

At that point both processes are in their critical sections.