我写了两个流程以满足互斥,但不确定是否是.. 我的初始标志值为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
}
事实上它们完全一样。
这两个过程是否满足互斥?
我无法看到违反了哪些要求..
答案 0 :(得分: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.