什么是并发性,并行性和异步方法之间的区别?

编程入门 行业动态 更新时间:2024-10-09 10:24:38
本文介绍了什么是并发性,并行性和异步方法之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

并发是具有并联在单独的线程中运行两个任务。但是,异步方法并行,但在相同的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.

更多推荐

什么是并发性,并行性和异步方法之间的区别?

本文发布于:2023-11-23 21:29:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622917.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   发性   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!