expression

Multi-thread runtime and worker count

Configure a runtime that can schedule tasks on multiple worker threads. A worker count is not a task count or a promise of parallel execution. Blocking pool threads are separate. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 9 Common mistake: Assuming every spawned task is permanently attached to its own OS thread.

Formal Syntax & Structure

rust syntaxrust
Builder::new_multi_thread().worker_threads(2).build()

Working Example

Example Snippetrust
fn main() {    let rt = tokio::runtime::Builder::new_multi_thread().worker_threads(2).build().unwrap();    let answer = rt.block_on(async {        tokio::spawn(async { 9u32 }).await.unwrap()    });    println!("{answer}");}
Rust Reference