I\'m currently training for an OS exam with previous iterations and I came across this:
Implement a "N Process Barrier", that is, making sure t
This is well presented in The Little Book of Semaphores.
n = the number of threads
count = 0
mutex = Semaphore(1)
barrier = Semaphore(0)
mutex.wait()
count = count + 1
mutex.signal()
if count == n: barrier.signal() # unblock ONE thread
barrier.wait()
barrier.signal() # once we are unblocked, it's our duty to unblock the next thread