Polling¶
Category: Scheduling · Status: stub
One line: Asking repeatedly whether something is ready instead of being told; in Rust, an executor polls a future and the future answers Ready or Pending.
Also called: poll.
How it connects¶
flowchart LR
n_async_runtime["Async runtime (executor and reactor)"]
n_polling["Polling"]
n_async_runtime -->|uses| n_polling
classDef center stroke-width:3px
class n_polling center
classDef outside stroke-dasharray: 4 3
class n_async_runtime outside
- Is used by: Async runtime (executor and reactor)
- See also: Blocking and non-blocking calls, Busy waiting, Future and promise
In each language¶
| Rust | Future::poll ↗ returns Poll::Ready ↗ or Poll::Pending, and a Waker ↗ says when to poll again |
| Go | A select with a default case ↗ checks channels without blocking |
| C++ | std::future::wait_for ↗ with a zero timeout asks whether a result is ready |
| Java | Future.isDone ↗, and poll on a BlockingQueue ↗ |
| Python | Popen.poll ↗ checks whether a child process has ended |
| The operating system | poll(2) ↗, despite its name, waits for a file descriptor to become ready |
Where to read more¶
- In the books: Asynchronous Programming in Rust, Carl Fredrik Samson — ch. 4, 'Create Your Own Event Queue' → 'The Poll module'
- In the books: Concurrency in C# Cookbook, Stephen Cleary — ch. 10, 'Cancellation' → 'Responding to Cancellation Requests by Polling'
- In the books: Kotlin Coroutines by Tutorials, Filip Babić, Nishant Srivastava — ch. 11, 'Channels' → 'Comparing receive and poll'
- In the books: Advanced Programming in the UNIX Environment, W. Richard Stevens, Stephen A. Rago — ch. 14, 'Advanced I/O' → 'poll Function'
- In the books: Python Cookbook, David Beazley, Brian K. Jones — ch. 12, 'Concurrency' → 'Polling Multiple Thread Queues'
- In the books: Programming Rust, Jim Blandy, Jason Orendorff, Leonora F. S. Tindall — ch. 20, 'Asynchronous Programming' → 'Primitive Futures and Executors: When Is a Future Worth Polling Again?'
- Notes: poll - polling - general ↗
- Notes: poll - rust ↗
- Reference: Wikipedia: Polling (computer science) ↗