Concurrency in Depth · 18 min · free with an account

Async vs Threads

Lesson preview · about 30%

Threads are for CPU work; async is for waiting.

Core idea

Async wins on concurrency; threads win on parallel computation.

Start with the idea

A thread costs a stack and a scheduler slot, which is fine for a few hundred and painful for a hundred thousand. Async tasks are state machines sharing a small pool of threads, so waiting on ten thousand sockets is cheap — but a task that computes without yielding blocks everything sharing its thread. The dividing line is whether the work waits or works.

A thread is an operating-system execution context; an async task is a future that an executor polls. The async task can yield during nonblocking waits, allowing one thread to serve many waiting operations. A thread can execute CPU work in parallel with other threads when cores are available. These distinctions are more useful than saying one technology is for all I/O and the other for all CPU.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep