Skip to content

Do I need to spawn to take advantage of a multi-threaded runtime? #3235

Answered by hawkw
sylvain101010 asked this question in Q&A
Discussion options

You must be logged in to vote

From what I understood from https://tokio.rs/blog/2019-10-scheduler the scheduler automatically balance the futures across all core threads,

The scheduler doesn't automatically balance futures across all core threads, it balances tasks. Tasks are lightweight units of work composed of one or more futures. Calling tokio::spawn or tokio::spawn_local with a future creates a new task that executes that future. awaiting a future in an async block or function waits for that future to complete as part of the current task.

Therefore, yes, in order to run work in parallel on multiple threads, it is necessary to spawn new tasks. Does that help?

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@sylvain101010
Comment options

@hawkw
Comment options

Answer selected by sylvain101010
Comment options

You must be logged in to vote
3 replies
@davidbarsky
Comment options

@hawkw
Comment options

@sylvain101010
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants