Does async runtime imply multi-thread / make stuff send+sync?

I'm studying website/ at master · tokio-rs/website · GitHub

One thing I am curious about is whether async runtime implies multi-thread / make stuff send+sync.

In particular, I am curious about an alternative setup where:

  1. we run one async runtime per thread

  2. msgs between asyncs on the same thread are cheaper

  3. msgs between asyncs on different threads cost a bit more


  1. does the above make any sense at all ?

  2. what would be the tradeoffs / why isn't the above used ?

In general, no. For example, Tokio supports creating runtime via Builder::new_current_thread, which, as the name suggests, will run all tasks on the thread it is created on (and does not require them to be Send, as a consequence).

Be aware that new_current_thread also requires tasks to be Send. The way to use non-Send tasks in Tokio us to use a LocalSet. The difference is that a Runtime object can be moved from one thread to another, but a LocalSet can't.

1 Like

@Cerber-Ursi @alice : Cool; thanks. I guess the high level bit here is that my original assumption was wrong: 1. async does not imply multi thread and 2. tokio already has async-pinned-on-a-thread runtimes.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.