【问题标题】:does my solution satisfy the requirements for a mutual exclusion我的解决方案是否满足互斥的要求
【发布时间】:2011-02-28 17:34:09
【问题描述】:

为了满足互斥,我写了 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

}

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

【问题讨论】:

    标签: process semaphore flags critical-section mutual-exclusion


    【解决方案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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 2016-04-26
      • 2019-09-15
      相关资源
      最近更新 更多