限制并发线程等于处理器的数量? [英] Limiting concurrent threads equal to number of processors?

查看:335
本文介绍了限制并发线程等于处理器的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有对限制并发线程的数量做一个给定的任务为等于主机系统上的处理器的数量的任何好处?或者更好地单纯的信任库,如.NET的线程池做正确的事情......即使有25个不同的并发线程在任何一个特定的时刻发生了什么?

Are there any benefits to limiting the number of concurrent threads doing a given task to equal the number of processors on the host system? Or better to simply trust libraries such as .NET's ThreadPool to do the right thing ... even if there are 25 different concurrent threads happening at any one given moment?

推荐答案

大多数线程不CPU限制,他们最终等待IO或其他事件。如果你现在在你的系统中的样子,我想你有100的(如果不是1000年)的线程,没有任何问题执行。通过这一措施,你可能只是最好离开.NET线程池做正确的事!

Most threads are not CPU bound, they end up waiting on IO or other events. If you look at your system now, I imagine you have 100's (if not 1000's) of threads executing with no problems. By that measure, you're probably best just leaving the .NET thread pool to do the right thing!

不过,如果线程都是CPU限制(例如像光线追踪),那么这将是一个不错的主意,以限制线程的内核数量的多少,否则有机会,上下文切换将开始影响性能。

However, if the threads were all CPU bound (e.g. something like ray tracing) then it would be a good idea to limit the number of threads to the number of cores, otherwise chances are that context switching will begin to hurt performance.

这篇关于限制并发线程等于处理器的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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