I am trying to implement the Reusable Barrier algorithm from "Little Book of Semaphores", but without using a counter. I thought about an implementation where I may use 4 barriers, but I cannot find a way of knowing when all threads have passed first two barriers for example. Also, another implementation that I thought about is with some boolean variables:
def threadA():
isOpenA = True
barrierA.wait()
isOpenA = False
barrierA.signal()
isOpenA = True
while isOpenA == True:
#hold threads here until each one arrives
#barrierB wait
#signal barrierB
Is there a possible way to implement the Reusable Barrier without using a counter?