问题
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?
回答1:
The full documentation on Barrier is here: https://docs.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.
来源:https://stackoverflow.com/questions/52615413/register-new-thread-to-already-defined-barrier