异步VS同步执行,这是什么究竟意味着什么? [英] Asynchronous vs synchronous execution, what does it really mean?

查看:109
本文介绍了异步VS同步执行,这是什么究竟意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是异步和同步执行的区别?

What is the difference between asynchronous and synchronous execution?

推荐答案

当您执行同步的东西,你等待它移动到另一个任务之前完成。当您执行异步的东西,你可以把它完成之前移动到另一项任务。

When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes.

这之中,说,这台计算机转化为执行另一个流程或任务的上下文线程。线程是一系列命令 - code块 - 存在作为一个工作单元。操作系统可以管理多个线程,并切换到另一个线程给它转一转做一些工作之前分配一个线程的处理器时间片(切片)。在它的核心(原谅双关语),处理器可以简单地执行一个命令 - 它没有在同一时间做两件事情的概念。操作系统通过分配的时间片不同的线程模拟这一点。

That being, said, in the context of computers this translates into executing a process or task on another "thread." A thread is a series of commands--a block of code--that exists as a unit of work. The operating system can manage multiple threads and assign a thread a piece ("slice") of processor time before switching to another thread to give it a turn to do some work. At its core (pardon the pun), a processor can simply execute a command--it has no concept of doing two things at one time. The operating system simulates this by allocating slices of time to different threads.

现在,如果你介绍多核/处理器混进去,那么事情可能实际发生在同一时间。操作系统可以在第一处理器上分配时间给一个线程,那么在相同的时间块分配给其他线程在不同的处理器。

Now, if you introduce multiple cores/processors into the mix, then things CAN actually happen at the same time. The operating system can allocate time to one thread on the first processor, then allocate the same block of time to another thread on a different processor.

这一切都是关于允许操作系统来管理你的任务完成,而你可以在code去和做其他事情。异步编程是因为事情是如何结合在一起时,你可以在同一时间做他们的语义复杂的话题。有关于这个问题的许多文章和书籍;看看!

All of this is about allowing the operating system to manage the completion of your task while you can go on in your code and do other things. Asynchronous programming is a complicated topic because of the semantics of how things tie together when you can do them at the same time. There are numerous articles and books on the subject; have a look!

这篇关于异步VS同步执行,这是什么究竟意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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