在C#4.0和阻隔区别的WaitHandle在C#3.0吗? [英] Difference between Barrier in C# 4.0 and WaitHandle in C# 3.0?

查看:120
本文介绍了在C#4.0和阻隔区别的WaitHandle在C#3.0吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我捡了C#4.0和它困惑我的事情之一,就是障碍的概念。

I am picking up C# 4.0 and one of the things which is confusing me, is the barrier concept.

这是不是就像使用<一个href="http://msdn.microsoft.com/en-us/library/system.threading.waithandle.waitall.aspx"><$c$c>WaitAll 的WaitHandle 的方法是什么?难道这不是等待所有线程完成?

Is this not just like using the WaitAll method of WaitHandle? Doesn't that wait for all threads to finish?

我学到这个页面的屏障建设:<一href="http://www.managed-world.com/archive/2009/02/09/an-intro-to-barrier.aspx">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.

这篇关于在C#4.0和阻隔区别的WaitHandle在C#3.0吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆