I have implemented a simple Cyclic Barrier but from quick test I have realised that if you set up a barrier for, say 2 threads, but have 4 threads about to reach the barrier.await() then you will get 2 instances of pairs of threads in the critical section at the same time. Similarly using 6 threads would get 3 pairs of threads in the critical section at the same time (haven’t tested very well as I am new to this)

My question is, if n threads pass the barrier and enter the critical section, how do I stop other groups of n threads entering the critical section while the critical section is already in use?

Thanks in advance.