每个处理器产生多个线程是有意义的吗? [英] Does it make sense to spawn more than one thread per processor?

查看:112
本文介绍了每个处理器产生多个线程是有意义的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从逻辑角度来看,应用程序可能需要几十或几百个线程,其中一些线程将在大多数时间内休眠,但是少数线程将始终并发运行。问题是:在系统中生成比处理器更多的并发线程有意义吗?还是浪费?

From a logical point of view an application may need dozens or hundreds of threads, some of which will we sleeping most of the time, but a very few will be always running concurrently. The question is: Does it make any sense to spawn more concurrent threads than processors there are in a system, or it is a waste?

我看过一些服务器应用程序实现一个调度程序来逻辑管理任务(通常称为作业),但也产生了很多线程,所以我看不到的好处是什么。

I've seen some server applications that implement a scheduler to logically manage tasks (often called jobs), but also spawning a lot of threads, so I don't see where the benefit is.

感谢。

推荐答案

当然。如果您的软件频繁使用磁盘或网络IO,您通常可以通过添加几个线程来提高吞吐量。这些额外的线程将被唤醒并做其他线程阻塞IO。

Sure. If your software makes frequent use of disk or network IO, you can often improve throughput by adding a few more threads. Those extra threads will be awake and doing stuff while the other threads are blocking on IO.

这篇关于每个处理器产生多个线程是有意义的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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