Register new thread to already defined barrier

北战南征 提交于 2019-12-25 00:16:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!