【发布时间】:2017-06-02 08:45:14
【问题描述】:
最近我看到这个问题与 First reader/writer problem 非常相似。
Implementing an N process barrier using semaphores
我正在尝试修改它以确保它可以重复使用并正常工作。
n = the number of threads
count = 0
mutex = Semaphore(1)
barrier = Semaphore(0)
mutex.wait()
count = count + 1
if (count == n){ barrier.signal()}
mutex.signal()
barrier.wait()
mutex.wait()
count=count-1
barrier.signal()
if(count==0){ barrier.wait()}
mutex.signal()
这是正确的吗?
我想知道是否存在一些我没有发现的错误。
【问题讨论】:
标签: operating-system computer-science semaphore systems-programming barrier