如何阐明异步和并行编程之间的区别? [英] How to articulate the difference between asynchronous and parallel programming?

查看:21
本文介绍了如何阐明异步和并行编程之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多平台将异步和并行作为提高响应能力的手段.我大体上理解其中的差异,但经常发现很难在我自己和其他人的脑海中表达出来.

Many platforms promote asynchrony and parallelism as means for improving responsiveness. I understand the difference generally, but often find it difficult to articulate in my own mind, as well as for others.

我是一名日常程序员,使用 async &回调相当频繁.并行性让人感觉异国情调.

I am a workaday programmer and use async & callbacks fairly often. Parallelism feels exotic.

但我觉得它们很容易混为一谈,尤其是在语言设计层面.希望清楚地描述它们之间的关系(或不相关),以及最适合应用的程序类别.

But I feel like they are easily conflated, especially at the language design level. Would love a clear description of how they relate (or don't), and the classes of programs where each is best applied.

推荐答案

当你异步运行某个东西时,这意味着它是非阻塞的,你无需等待它完成就可以执行它并继续处理其他事情.并行意味着同时并行运行多个事物.当您可以将任务分成独立的工作部分时,并行处理效果很好.

When you run something asynchronously it means it is non-blocking, you execute it without waiting for it to complete and carry on with other things. Parallelism means to run multiple things at the same time, in parallel. Parallelism works well when you can separate tasks into independent pieces of work.

以渲染 3D 动画的帧为例.渲染动画需要很长时间,因此如果您要从动画编辑软件中启动该渲染,您需要确保它异步运行,这样它就不会锁定您的 UI,您可以继续做其他事情.现在,该动画的每一帧也可以被视为一项单独的任务.如果我们有多个 CPU/内核或多台机器可用,我们可以并行渲染多个帧以加快整体工作负载.

Take for example rendering frames of a 3D animation. To render the animation takes a long time so if you were to launch that render from within your animation editing software you would make sure it was running asynchronously so it didn't lock up your UI and you could continue doing other things. Now, each frame of that animation can also be considered as an individual task. If we have multiple CPUs/Cores or multiple machines available, we can render multiple frames in parallel to speed up the overall workload.

这篇关于如何阐明异步和并行编程之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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