在一个内核上同时执行2个以上的线程,是否可能? [英] Execute more than 2 threads simultaneously on one core, is it possible?

查看:104
本文介绍了在一个内核上同时执行2个以上的线程,是否可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机中有一个核心。



我可以在任何给定时刻使用线程同时分别执行2个不同的代码来提高性能吗?



或者一个核心只有一个执行管道?



换句话说,是否可以同时执行几个代码在一个核心上使用线程或定时器的任何给定时刻?

I have one core in my computer.

Can i use threads to execute 2 different codes separately simultaneously at any given moment to improve performance?

Or one core has only one execution pipeline?

In other words, is it possible to execute a few codes simultaneously at any given moment on one core using threads or timers?

推荐答案

通常,您可以根据需要创建任意数量的线程,OS / Cpu将管理调度和执行。



试试看是一般的答案,因为我们不知道您的应用程序是什么以及如何编写。
Generally you can create as many threads as you need and the OS/Cpu will manage the scheduling and execution.

Try and see is the general answer since we have no clue as what your app is and how it is written.


引用:

我不是英特尔系统中多处理的专家,但我认为最好的方法是看一个核心不能同时执行两条指令。这可能在技术上不正确,因为硬件可能会将指令拆分成单独的部分并同时执行不同的部分。



我的理解是,如果你运行两个线程在一个核心上,线程之间切换会产生一些开销,这会使整个过程变得更慢。因此,如果你有一个全部计算的工作(比如将Pi计算到大量的小数位),如果每个核心有一个活动线程,你将完成最快。但是,如果您正在执行的作业暂停,而没有执行任何指令(例如,如果它正在等待输入,或者正在读取的数据),则操作系统可能能够在一个线程中填充这些暂停另一个线程的有用工作。如果恢复的时间足以弥补切换线程的开销,那将加快你的工作。



例如,如果你在一个线程中运行你的工作在单核上,任务管理器将CPU显示为75%忙碌,那么使用多个线程最好的方法就是让CPU 100%忙碌(大约提高33%)。

I'm not an expert on multiprocessing in Intel systems, but I think the best way to look at it is that one core cannot execute two instructions at the same time. That may not be technically correct as the hardware may split an instruction into separate parts and execute different parts at the same time.

My understanding is that if you run two threads on one core, there will be some overhead associated with switching between the threads which will tend to make the whole process slower. So if you have a job that is all calculation (like calculating Pi to a large number of decimal places), you will finish the fastest if you have one active thread per core. However, if the job you are doing has pauses where no instructions are being executed (for example if it is waiting for input, or for data that is being read), then the operating system may be able to fill those pauses in one thread with useful work from another thread. That will speed up your job if the time recovered is enough to make up for the overhead of switching threads.

For example, if you run your job in a single thread on a single core and Task Manager shows the CPU as 75% busy, then the best you could hope for by using multiple threads is to make the CPU 100% busy (about a 33% improvement).





https://social.msdn.microsoft.com/Forums/en-US/858674a9-0ede-481e-bd80-2d4c8f8c7787/timer-vs-thread-is-执行中的差异 [ ^ ]


这篇关于在一个内核上同时执行2个以上的线程,是否可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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