最大限制可以在多线程中创建线程
我有多个线程同时被其他几个进程调用。一般来说,最大的经验法则是。处理器可以启动提供性能效率的线程数是没有。线程数 = 数。处理器数量 + 1(但不确定)。所有现代应用程序都维护一个线程池,并在任何特定实例中继续重用线程。
我们如何确保性能不会因此而下降。因为当超出限制时,线程会继续进行上下文切换,并且在任何单一点,它们都不会执行代码的关键部分。
I have multiple threads being invoked by say several other processes at the same time. Generally the thumb rule for max. number of threads that a processor can start giving performance efficiency is no. of threads = no. of processors + 1 (not sure though). All the modern applications maintain a threadpool and keep on re-using threads at any particular instance.
How can we make sure that performance won't degrade due to this. Because when it goes beyond the limit, threads keep on context switching and at any singe point, none of them will be executing the critical section of the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
线程的数量更多地取决于它使用的资源。
如果线程处理来自磁盘或网络的数据,则取决于它必须等待该资源的时间。在等待期间,另一个线程可以做一些工作。
对于纯粹的数字运算,我会说每个处理器/核心一个线程。
The number of threads is more dependend on the resources it uses.
If the thread processes data from disk or network, it depends on how long it has to wait on that resources. During the wait another thread can do some work.
For pure number crunching I would say one thread per processer/core.