什么是并发性,并行性和异步方法之间的区别? [英] What is the difference between concurrency, parallelism and asynchronous methods?

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

问题描述

并发是具有并联在单独的线程中运行两个任务。但是,异步方法并行,但在相同的1线程中运行。这是如何实现的?还等什么有关并行?

Concurrency is having two tasks run in parallel on separate threads. However, asynchronous methods run in parallel but on the same 1 thread. How is this achieved? Also, what about parallelism?

这些是什么三个概念之间的区别是什么?

What are the differences between these 3 concepts?

推荐答案

并发和并行实际上是相同的原则,正确推测,两者都涉及到的任务同时被执行,虽然我会说,并行任务应该是真正的多任务处理,执行同时,而同时可能意味着任务共享执行线程,同时还出现在并行地执行。

Concurrent and parallel are effectively the same principle as you correctly surmise, both are related to tasks being executes simultaneously although I would say that parallel tasks should be truly multitasking, executed "at the same time" whereas concurrent could mean that the tasks are sharing the execution thread while still appearing to be executing in parallel.

异步方法没有直接关系到previous两个概念,异步用于present并发或并行任务的即时pression但有效的异步方法调用通常用于处理需要做的工作,从目前的应用了,我们不想等待,阻止我们的应用程序等待响应。

Asynchronous methods aren't directly related to the previous two concepts, asynchrony is used to present the impression of concurrent or parallel tasking but effectively an asynchronous method call is normally used for a process that needs to do work away from the current application and we don't want to wait and block our application awaiting the response.

例如,从数据库中获取的数据可能需要时间,但我们不希望阻止我们的UI等待数据。在非同步调用需要一个回调参考,并尽快申请已被放置与远程系统返回执行回你的code。你的UI能继续响应用户,同时也需要在远程系统上的任何处理,一旦它返回的数据到你的回调方法,那么该方法可以更新UI(或者手头宽裕的更新)为宜。

For example, getting data from a database could take time but we don't want to block our UI waiting for the data. The asynch call takes a call-back reference and returns execution back to your code as soon as the request has been placed with the remote system. Your UI can continue to respond to the user while the remote system does whatever processing is required, once it returns the data to your call-back method then that method can update the UI (or hand off that update) as appropriate.

这看起来像多任务用户的角度来看,但它可能不是。

From the User perspective it appears like multitasking but it may not be.

修改

这也许值得补充说,在许多实现异步方法调用会导致线程被剥离了,但它不是必需的,它实际上取决于操作执行和响应如何被通知回系统。

It's probably worth adding that in many implementations an asynchronous method call will cause a thread to be spun up but it's not essential, it really depends on the operation being executed and how the response can be notified back to the system.

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

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