Eloquent Javascript 书中的第 181 页第 11 章:异步编程中给出的图表中的间隙是什么意思?
What do the gaps mean in the diagram given in page 181, chapter 11: Asynchronous programming in the book Eloquent Javascript?
我正在阅读“Eloquent Javascript”,关于异步编程的第 11 章,第 181 页给出了一张图表,对比了单线程、多线程和异步技术在这种情况下的差异发送两个网络请求。黑点代表时间线中提出请求的点。细线表示等待响应所花费的时间。粗线表示正常的程序执行。我的疑问是时间轴上的差距。作者没有提到它们代表什么,所以我很难准确区分这些概念。感谢任何帮助理解。
An asynchronous model allows multiple things to happen at the same time.
When you start an action, your program continues to run. When the action
finishes, the program is informed and gets access to the result (for example,
the data read from disk).
We can compare synchronous and asynchronous programming using a small
example: a program that fetches two resources from the network and then
combines results.
In a synchronous environment, where the request function returns only after
it has done its work, the easiest way to perform this task is to make the requests
one after the other. This has the drawback that the second request will be
started only when the first has finished. The total time taken will be at least
the sum of the two response times.
The solution to this problem, in a synchronous system, is to start additional
threads of control. A thread is another running program whose execution may
be interleaved with other programs by the operating system—since most modern computers contain multiple processors, multiple threads may even run at
the same time, on different processors. A second thread could start the second
request, and then both threads wait for their results to come back, after which
they resynchronize to combine their results.
In the following diagram, the thick lines represent time the program spends
running normally, and the thin lines represent time spent waiting for the net-
work. In the synchronous model, the time taken by the network is part of the
timeline for a given thread of control. In the asynchronous model, starting a
network action conceptually causes a split in the timeline. The program that
initiated the action continues running, and the action happens alongside it,
notifying the program when it is finished.
我会说差距代表将控制权交还给更高的实例。对于 JavaScript,这个更高的实例将是浏览器,然后浏览器将使用中间的时间来呈现页面或执行其他任务。对于通用进程,更高级别的实例是操作系统,它将安排另一个进程的执行,或者如果没有其他进程存在,则物理关闭处理器一小段时间。
我正在阅读“Eloquent Javascript”,关于异步编程的第 11 章,第 181 页给出了一张图表,对比了单线程、多线程和异步技术在这种情况下的差异发送两个网络请求。黑点代表时间线中提出请求的点。细线表示等待响应所花费的时间。粗线表示正常的程序执行。我的疑问是时间轴上的差距。作者没有提到它们代表什么,所以我很难准确区分这些概念。感谢任何帮助理解。
An asynchronous model allows multiple things to happen at the same time. When you start an action, your program continues to run. When the action finishes, the program is informed and gets access to the result (for example, the data read from disk).
We can compare synchronous and asynchronous programming using a small example: a program that fetches two resources from the network and then combines results.
In a synchronous environment, where the request function returns only after it has done its work, the easiest way to perform this task is to make the requests one after the other. This has the drawback that the second request will be started only when the first has finished. The total time taken will be at least the sum of the two response times.
The solution to this problem, in a synchronous system, is to start additional threads of control. A thread is another running program whose execution may be interleaved with other programs by the operating system—since most modern computers contain multiple processors, multiple threads may even run at the same time, on different processors. A second thread could start the second request, and then both threads wait for their results to come back, after which they resynchronize to combine their results.
In the following diagram, the thick lines represent time the program spends running normally, and the thin lines represent time spent waiting for the net- work. In the synchronous model, the time taken by the network is part of the timeline for a given thread of control. In the asynchronous model, starting a network action conceptually causes a split in the timeline. The program that initiated the action continues running, and the action happens alongside it, notifying the program when it is finished.
我会说差距代表将控制权交还给更高的实例。对于 JavaScript,这个更高的实例将是浏览器,然后浏览器将使用中间的时间来呈现页面或执行其他任务。对于通用进程,更高级别的实例是操作系统,它将安排另一个进程的执行,或者如果没有其他进程存在,则物理关闭处理器一小段时间。