What is the difference between busy-wait and polling?

前端 未结 2 468
[愿得一人]
[愿得一人] 2020-12-14 04:57

From the Wikipedia article on Polling

Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by

2条回答
  •  臣服心动
    2020-12-14 05:30

    The difference between the two is what the application does between polls.

    If a program polls a device say every second, and does something else in the mean time if no data is available (including possibly just sleeping, leaving the CPU available for others), it's polling.
    If the program continuously polls the device (or resource or whatever) without doing anything in between checks, it's called a busy-wait.

    This isn't directly related to synchronization. A program that blocks on a condition variable (that should signal when a device or resource is available) is neither polling nor busy-waiting. That's more like event-driven/interrupt-driven I/O.
    (But for example a thread that loops around a try_lock is a form of polling, and possibly busy-waiting if the loop is tight.)

提交回复
热议问题