开发者

How to make PLINQ to spawn more concurrent threads in .NET 4.0 beta 2?

开发者 https://www.devze.com 2022-12-11 22:44 出处:网络
In former versions of Parallel Extensions you could s开发者_高级运维et the number of threads: enumerable.AsParallel(numberOfThreads)

In former versions of Parallel Extensions you could s开发者_高级运维et the number of threads:

enumerable.AsParallel(numberOfThreads)

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


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

IE:

enumerable.AsParallel().WithDegreeOfParallelism(numberOfThreads)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号