Skip to main content

Module thread_roles

Module thread_roles 

Source
Expand description

Which of srv’s threads are the async runtime’s workers.

A blocking call is a different problem on a worker (the rest of srv’s tasks wait for it) than on a thread of the blocking pool or a thread srv started itself (only that call waits). Tokio gives no way to ask which one a thread is, but it launches the workers while the runtime is built, before any blocking task can exist: the threads that start before settle is called are the workers. main hands thread_started to the runtime’s on_thread_start and calls settle once the runtime is built; anything that never does (a test, a helper binary) sees no worker.

Functions§

on_worker
Whether the calling thread is one of the runtime’s workers.
settle
Called once the runtime is built, with its worker count: waits (a short while at most) for that many threads to have started, then marks every later thread as not a worker.
thread_started
Called by each thread the runtime starts, on that thread.