最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

异步与同步执行,主要区别是什么?

网站源码admin23浏览0评论
本文介绍了异步与同步执行,主要区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

异步和同步执行有什么区别?

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.

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

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. 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!

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

发布评论

评论列表(0)

  1. 暂无评论