最近我遇到了一个问题,它与第一读者/写者问题非常相似。
我正在尝试修改它,以确保它可以重复使用并正常工作。
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()
这个对吗?
我在想是否有一些我没有发现的错误。