0

Is there a way to add a thread to already pre-defined barrier?

The scenario: I have at certain point of time N threads, and the code declares the Barrier in order to handle them.

The problem is, that sometimes I may need another new thread to be handled inside that barrier instance, but the barrier has already been declared with N threads only.

Example:

barrier = new Barrier(N, (sprint) => { 
       Console.WriteLine($"Current sprint: {sprint.CurrentPhaseNumber}")
});

After the declaration I need to update it again somehow with N+1 threads, any suggestions?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91

1 Answers1

2

The full documentation on Barrier is here: https://learn.microsoft.com/en-us/dotnet/standard/threading/barrier

In a nutshell, you can add or remove a participant at any time by calling respectively AddParticipant or RemoveParticipant.

Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94