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
Only 2 barrier semaphores, but not sure...
semaphore barr[0..1] # two semaphores: barr[0] and barr[1]
semaphore excl=1
int count=0
int whichOne=0 # select semaphore to avoid race conditions
barr[0]=0 #initialization
barr[1]=0
# sample use
int current #local for each thread
wait(excl)
current=whichOne
count=count+1
if (count==N)
int j=1
while (j<=N)
signal(barr[current])
j=j+1
count=0
whichOne=1-whichOne # swap barrier to avoid race conditions
signal(excl)
wait(barr[current])