0

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?

Evan Carroll
  • 71,692
  • 44
  • 234
  • 400

1 Answers1

3

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.

kmdreko
  • 25,172
  • 5
  • 32
  • 61