public static async Task CorrectGarbageCollection() { for (int j = 0; j < 10; j++) { Task t1, t2; using (var barrier = new AsyncBarrier(3)) { t1 = barrier.SignalAndWait(); t2 = barrier.SignalAndWait(); await barrier.SignalAndWait(); GC.Collect(); await Task.WhenAll(t1, t2); } } }
public static async Task RemovingWaitingParticipants() { using (var barrier = new AsyncBarrier(4)) { var task = barrier.SignalAndWait(); while (barrier.ParticipantsRemaining > 3) { await Task.Delay(100); } barrier.RemoveParticipants(2); Equal(1, barrier.ParticipantsRemaining); Throws <ArgumentOutOfRangeException>(() => barrier.RemoveParticipants(20)); Equal(1, barrier.ParticipantsRemaining); barrier.RemoveParticipant(); Equal(0, barrier.ParticipantsRemaining); } }
public static async Task PhaseCompletion() { using (var barrier = new AsyncBarrier(3)) { ICollection <Task> tasks = new LinkedList <Task>(); Equal(0, barrier.CurrentPhaseNumber); tasks.Add(barrier.SignalAndWait()); tasks.Add(barrier.SignalAndWait()); tasks.Add(barrier.SignalAndWait()); await Task.WhenAll(tasks); Equal(1, barrier.CurrentPhaseNumber); tasks.Clear(); tasks.Add(barrier.SignalAndWait()); tasks.Add(barrier.SignalAndWait()); tasks.Add(barrier.SignalAndWait()); await Task.WhenAll(tasks); Equal(2, barrier.CurrentPhaseNumber); } }