A minimum working example:
#[tokio::main(flavor = "current_thread")]
async fn main() {
tokio::fs::File::open("./test.txt").await;
}
tokio version: latest 1.22.0
Rust version: 1.65.0
OS: Ubuntu 22.04
After compiling this program, I run this binary under QEMU user-mode to log each instruction's tid, and find out that there are two threads in this application (and maybe it is because File::open
calls spawn_blocking
).
In tokio's doc, it is said that
To use the single-threaded runtime known as the
current_thread
runtime, the macro can be configured usingflavor = "current_thread"
In my understanding, coroutine works as control flow is actively transmitted to runtime. I wonder why another thread is needed if I configured it to be current_thread
.