At the lowest (or at least the lowest cost) hardware level, asynchronous operations are truly asynchronous on modern operating systems.
For example, when you read a file from a disk, the operating system transfers your call to read to a number of disk operations (finding a location, reading X blocks through Y, etc.). In most modern operating systems, these commands are written either to special registers or to special places in the main memory, and the disk controller is informed that operations are expected. Then the operating system continues its activities, and when the disk controller has completed all the operations assigned to it, it launches interrupt , causing a thread that requested a read where it left off.
Regardless of what type of low-level asynchronous operation you are viewing (disk I / O, network I / O, mouse and keyboard input, etc.), there is ultimately some stage where the hardware command is sent, and a “callback” is not performed until the hardware reaches and informs the OS that it is done, usually in the form of an interrupt.
Not to say that there are no asynchronous operations implemented using polling. One trivial (but naive and expensive) way to implement any blocking operation asynchronously is to simply create a thread that waits for the operation to complete (possibly polling in a narrow loop), and then call the callback when it is complete. Generally speaking, general asynchronous operations at the OS level are truly asynchronous.
It is also worth mentioning that just because blocking an API does not mean polling it: you can put a blocking API on an asynchronous operation and a non-blocking API on a synchronous operation. For example, with things like select and kqueues, the stream actually just goes to bed until something interesting happens. This “something interesting” happens as an interrupt (usually), and this is considered a sign that the operating system needs to wake up the appropriate threads in order to continue working. He is not just sitting there in a narrow loop, waiting for something.
It is not possible to determine whether the system uses polls or "real" callbacks (for example, interrupts) only from its API, but yes, there are asynchronous APIs that are actually supported by asynchronous operations.
Matt patenaude
source share