gpt4 book ai didi

multithreading - 忙等待和轮询有什么区别?

转载 作者:行者123 更新时间:2023-12-04 02:35:26 24 4
gpt4 key购买 nike

来自维基百科文章 Polling

Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity. Polling is most often used in terms of input/output (I/O), and is also referred to as polled I/O or software driven I/O.

Polling is sometimes used synonymously with busy-wait polling (busy waiting). In this situation, when an I/O operation is required the computer does nothing other than check the status of the I/O device until it is ready, at which point the device is accessed. In other words the computer waits until the device is ready.
Polling also refers to the situation where a device is repeatedly checked for readiness, and if it is not the computer returns to a different task. Although not as wasteful of CPU cycles as busy-wait, this is generally not as efficient as the alternative to polling, interrupt driven I/O.


那么,当一个线程不使用“条件变量”时,它会被称为“轮询”数据更改还是“忙等待”?

最佳答案

两者之间的区别在于应用程序在轮询之间执行的操作。

如果程序每秒轮询一次设备,并且在没有数据可用的情况下同时执行其他操作(包括可能只是休眠,将 CPU 留给其他人使用),则它正在轮询。
如果程序连续轮询设备(或资源或其他)而不在检查之间做任何事情,则称为忙等待。

这与同步没有直接关系。在条件变量上阻塞的程序(应该在设备或资源可用时发出信号)既不是轮询也不是忙等待。这更像是事件驱动/中断驱动的 I/O。
(但例如,一个围绕 try_lock 循环的线程是一种轮询形式,如果循环紧张,可能会忙等待。)

关于multithreading - 忙等待和轮询有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10594426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com