多道技术、同步异步和阻塞非阻塞

前期需要储备的知识点

并发

看起来同时运行的就可以称之为并发,其实内部是做了0.1秒A,做了0.1秒B,交替进行运作,看起来像是一起运作的。

并行

真正意义上的同时执行

补充

1.并行肯定算是并发
2.单核的计算机肯定不能实现并行,但是可以实现并发!!
3.我们这里的单核是假设就是一个核,干活的就一个人,不考虑cpu里面的内核

1. 多道技术

1.1 什么是多道技术

简单地说,就是单核技术实现协同效应。

[En]

To put it simply, it is the technology of single core to achieve concurrent effect.

图解:

多道技术、同步异步和阻塞非阻塞

1.2 为什么要有多道技术

多通道技术可以节省运行多个程序的总时间(时间重用),也可以让多个程序共享一套计算机硬件(空间重用)。

[En]

Multi-channel technology can save the total time of running multiple programs (time reuse), and can also allow multiple programs to share a set of computer hardware (space reuse).

2. 同步与异步

同步和异步描述了如何提交任务。

[En]

Synchronous and asynchronous describe how tasks are submitted.

2.1 同步

同步是指任务提交后,原地等待任务的返回结果,在等待过程中不做任何事情(等待)

[En]

Synchronization means that after the task is submitted, wait in place for the return result of the task, and do nothing during the waiting process (waiting)

2.2 异步

异步意味着在提交任务后,它等待任务的返回结果,并在等待期间执行其他任何操作。

[En]

Asynchronism means that after a task is submitted, it waits for the return result of the task and does anything else while waiting.

问题是,如何才能获得提交的结果?任务的返回结果将由一个异步回调机制自动处理!

[En]

The question is, how can the submitted results be obtained? The returned result of the task will be handled automatically by an asynchronous callback mechanism!

3. 阻塞与非阻塞

阻塞和非阻塞描述程序的运行状态。

[En]

Blocking and non-blocking describe the running state of the program.

阻塞:阻塞态

非阻塞:就绪和运行态

理想情况下,我们应该让我们的程序永远在就绪和运行之间切换。

[En]

Ideally, we should keep our program forever switching between ready and running.

上述概念的组合:最高效的一种组合就是异步非阻塞!

Original: https://www.cnblogs.com/suncolor/p/16612700.html
Author: 等日落
Title: 多道技术、同步异步和阻塞非阻塞

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/498673/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球