6. ConcurrencyAsync vs threads vs processes
Async vs threads vs processes
Async, threads and processes are three ways for a program to do several things at once, each suited to different work. Async runs many tasks on one thread, and each task pauses wherever it would wait, like a network call, so the thread can run another; it’s cheap per task and ideal when most time is spent waiting on I/O. Threads are scheduled by the operating system and can run in parallel on many cores while sharing memory, which is convenient but needs locks. Processes share no memory by default, so they’re isolated and safe but costlier to communicate between. A rough rule: async for lots of waiting, threads or processes for heavy computation, and processes in Python, because of the GIL.
In this lesson: Choose an I/O-bound or CPU-bound workload and compare throughput.