Open wonrax opened 1 week ago
Looking through the Tokio codebase, it seems like the parking mechanism is actually implemented by the I/O driver or the timer driver. If neither driver is enabled, Tokio will fall back to parking the thread using a condition variable or thread parking.
If the I/O driver is enabled, it uses Linux's epoll
syscall with a timeout parameter to park the thread until a point where a timer entry needs to be woken up (this is useful for our ongoing implementation of wheel timer). If there's a new task before the timer expires, Tokio will manually fire a fake (?) I/O event to make epoll
return.
If the I/O driver is not enabled but the timer driver is, the timer driver will park the thread using a condition variable, similarly with a timeout of the duration until the next timer entry expires.