Using Barrier to Implement Go's Wait Group
if (WaitGroupBarrier.ParticipantsRemaining &gt; 0) {
    WaitGroupBarrier.SignalAndWait();
}


The above is a non-atomic operation. Thus if the if branch gets evaluated and there is one remaining, but finishes before SignalAndWait, then this will throw an exception.