I am picking up C# 4.0 and one of the things which is confusing me, is the barrier concept.
Is this not just like using the WaitAll method of WaitHandle? Doesn’t that wait for all threads to finish?
I learnt the barrier construct from this page: http://www.managed-world.com/archive/2009/02/09/an-intro-to-barrier.aspx
However, it seems just like the WaitAll method. What am I missing? What’s the difference here?
Thanks.
It sounds like you are curious as to why a Barrier would be preferred over a WaitHandle + WaitForAll derivative? Both can achieve a similar goal if structured properly.
I’m not extremely familiar with Barrier but one advantage that jumps out at me is a resource issue. To synchronize N threads with a Barrier requires only a single Barrier instance. To synchronize N threads via a WaitHandle and WaitAll requires N handles. These resources are cheap but not free. Reducing the number of resources to synchronize a group of threads has it’s advantages.