Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

asynchronous - 异步与同步执行的真正含义是什么? [等候接听](Asynchronous vs synchronous execution, what does it really mean? [on hold])

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

  ask by tush1r translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!

(看一看!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...