我捡了C#4.0和它困惑我的事情之一,就是障碍的概念。
I am picking up C# 4.0 and one of the things which is confusing me, is the barrier concept.
这是不是就像使用WaitAll 的WaitHandle
的方法是什么?难道这不是等待所有线程完成?
Is this not just like using the WaitAll
method of WaitHandle
? Doesn't that wait for all threads to finish?
我学到这个页面的屏障建设:http://www.managed-world.com/archive/2009/02/09/an-intro-to-barrier.aspx
I learnt the barrier construct from this page: http://www.managed-world.com/archive/2009/02/09/an-intro-to-barrier.aspx
不过,这似乎就像为WaitAll
方法。我在想什么?这里有什么区别呢?
However, it seems just like the WaitAll
method. What am I missing? What's the difference here?
感谢。
推荐答案
听起来你很好奇,为什么一个障碍将是pferred过的WaitHandle + WaitForAll衍生$ P $?两者都可以实现类似的目标,如果结构正常。
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.
我不十分熟悉的障碍只有一个优点,即跳出我是一个资源问题。要同步N个线程有障碍只需要一个屏障实例。要通过同步的WaitHandle N个线程,并为WaitAll需要N把手。这些资源是便宜,但不是免费。减少资源的数量来同步一组线程具有它的优点。
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.
相关推荐
最新文章