If my code has
#[tokio::main]
async fn main() {
// mutates a global read-only variable "unsafe"
Will that mutation on the global read-only variable happen before or after Tokio sets up its thread pool?
If my code has
#[tokio::main]
async fn main() {
// mutates a global read-only variable "unsafe"
Will that mutation on the global read-only variable happen before or after Tokio sets up its thread pool?
From the tokio documentation:
#[tokio::main] async fn main() { println!("Hello world"); }Equivalent code not using
#[tokio::main]fn main() { tokio::runtime::Builder::new_multi_thread() .enable_all() .build() .unwrap() .block_on(async { println!("Hello world"); }) }
So the code in async fn main() is run by the executor, after its been started.