0

我写了 2 个进程以满足互斥,但不确定是否是 .. 我的初始标志值为 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

}

事实上它们是完全一样的。这两个过程是否满足互斥?我看不到违反了什么要求..

4

1 回答 1

1
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.
于 2011-02-28T17:38:17.980 回答