如何使 PLINQ 在 .NET 4.0 beta 2 中产生更多并发线程?

发布于 2024-08-12 12:59:01 字数 121 浏览 3 评论 0原文

在以前版本的并行扩展中,您可以设置线程数:

enumerable.AsParallel(numberOfThreads)

但现在该重载不再可用。现在该怎么做呢?

In former versions of Parallel Extensions you could set the number of threads:

enumerable.AsParallel(numberOfThreads)

But now that overload is not available anymore. How to do it now?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晚雾 2024-08-19 12:59:01

在新版本中,您可以使用扩展方法“.WithDegreeOfParallelism(int DegreeOfParallelism)”来指定它。

IE:

enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads)

In the new version you can specify it with the extension method ".WithDegreeOfParallelism(int degreeOfParallelism)".

IE:

enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads)
平安喜乐 2024-08-19 12:59:01

我真的不知道为什么会改变,所以我无法回答这个问题,但似乎如果开发人员指定了线程数,那么并行运行时将无法基于最佳方式执行操作在当前可用的硬件线程上。

我不想指定线程数。 PLINQ 的美妙之处在于它只是并行,而无需我弄清楚任何线程逻辑。

I really have no idea why it changed, so I can't answer the question, but it seems like if the developer specifies the number of threads, then the parallel runtime won't be able to perform the operation in the most optimal way based on the currently available hardware threads.

I don't want to specify number of threads. The beauty of PLINQ is that it just goes parallel without me having to figure out any threading logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文