// initialize with 2 participant
using var barrier = new AsyncBarrier(2);
var task1 = Task.Run(async () =>
{
await barrier.SignalAndWaitAsync();
Console.WriteLine(barrier.ParticipantsRemaining);
return -42;
});
var task2 = Task.Run(async () =>
{
await barrier.SignalAndWaitAsync();
Console.WriteLine(barrier.ParticipantsRemaining);
return 42;
});
var result = await Task.WhenAll(task1, task2);
will print:
2
2
while this one
// initialize with 1 participant and call AddParticipant after
using var barrier = new AsyncBarrier(1);
barrier.AddParticipant();
var task1 = Task.Run(async () =>
{
await barrier.SignalAndWaitAsync();
Console.WriteLine(barrier.ParticipantsRemaining);
return -42;
});
var task2 = Task.Run(async () =>
{
await barrier.SignalAndWaitAsync();
Console.WriteLine(barrier.ParticipantsRemaining);
return 42;
});
var result = await Task.WhenAll(task1, task2);
will print
1
1
I'm expecting the second snippet to behave like the first one.
I'm using version 4.14.2 from Nuget
This snippet
will print:
while this one
will print
I'm expecting the second snippet to behave like the first one. I'm using version
4.14.2
from Nuget