What is Asynchronous (Means Concurrent)?
PLEASE NOTE: Green threads and async are related but not same concepts
Green threads, runtime does M:N thread scheduling over OS Threads
Async, 1 thread executing task concurrently
Model runs larger number of tasks on a limited number of threads, because the per-task overhead is typically very low.
Eg: I/O-bound tasks(Network or file I/O)
Async vs Threading
| Async | Threading | |
|---|---|---|
| Concurrency | Done inside single thread. Uses event loops or similar mechanisms to efficiently handle tasks | Executing multiple threads of execution concurrently. |
| Resource Overhead | lower resource overhead compared to multithreading. Since reduces context-switching and memory overhead | High resource overhead. Since each thread has its own stack and context |
| Complexity | Simpler for certains cases like I/O-bound operations bcoz avoids deadlocks, race conditions | More complex since it involves race conditions, deadlocks, and other concurrency issues |
| Performance | Better performance for I/O-bound applications. Not suited for CPU-bound tasks. | Better performance for CPU-bound tasks |