Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...