并发和多线程之间的区别是什么? [英] What is the differene between concurrency and multithreading?

查看:58
本文介绍了并发和多线程之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

并发和多线程之间的区别是什么?只能在多核CPU中进行并发吗?有人可以举例说明吗?

What is the differene between concurrency and multithreading? Is concurrency only possible in multicore cpu? can anybody explain it with an example?

推荐答案

并发和多线程之间的区别是什么?

What is the differene between concurrency and multithreading?

并发描述了进程运行的方式.它们可以是顺序的(一个接一个),并发的(可以同时"进行,尽管不一定要在同一时刻进行)或并行的(它们可以同时发生).

Concurrency describes the way in which processes run. They are either sequential (one after another), concurrent (able to make progress "at the same time" although not necessarily at the same instant), or parallel (they happen simultaneously).

多线程是一种分配执行线程的技术.它们本质上是轻量级进程,相对于其父级的共享资源而言,具有一些优势.

Multi-threading is a technique which allocates individual threads of execution; they are essentially lightweight processes with some advantages with respect to shared resources from their parent.

如果您密切关注,则在并发和非并发系统上都可以使用多线程.线程是轻量级进程(相对于进程);因此,在非并行系统上具有多个线程不会导致并行编程.它们仍将开始运行直到完成.在并发系统上,它们每个都将在某个CPU时间上获得应有的份额.他们将全部同时取得进展 .

If you pay close attention, multi-threading is possible on both concurrent and non-concurrent systems. A thread is a lightweight process (with respect to processes); so, having multiples of threads on a non-concurrent system would not result in parallel programming. They would still start and run until finished before the other. And on a concurrent system they would each get their fair share at some CPU time; they would all be making progress concurrently.

仅在多核cpu中并发吗?

Is concurrency only possible in multicore cpu?

我想我们现在知道了,答案是否定的.并发执行进程是理所当然的,因为它被广泛误解为并行性.一个更强大的工具.

I think we know now, the answer to this is no. Concurrent execution of processes is taken for granted to the point it's widely misunderstood as parallelism; a much more powerful tool.

要给出一个提供一些见解的示例,请考虑您的机器.它一直在做各种各样的事情,而您不是(希望)在性能上有任何滞后.所有这些进程同时运行,即使在单台核心计算机上,也给用户带来并行感(我知道原因,我很老:)).

To give an example that provides some insight, think about your machine. It does all kinds of stuff all the time and you do not (hopefully) experience any lag in its performance. All these processes are running concurrently giving you, the user, a perception of parallelism even when on a single core machine (I know cause I'm old :)).

但是合并排序呢?我们不能对两半数据同时执行两个合并排序吗?是的.但前提是我们有多个内核/CPU.

But what about a merge sort? Couldn't we perform two merge sorts simultaneously on two halves of the data; yes. But only if we have multiple cores/CPUs.

这篇关于并发和多线程之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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