Modification to “Implementing an N process barrier using semaphores”
问题 Recently I see this problem which is pretty similar to First reader/writer problem. Implementing an N process barrier using semaphores I am trying to modify it to made sure that it can be reuse and work correctly. 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() Is this correct? I