Comparisons and explanations · Intermediate

Threads versus asynchronous processing

Compare scheduled threads with asynchronous tasks, distinguishing concurrency, parallelism, blocking work and resource limits.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Concurrency is not identical to parallel execution
  2. Overlap independent external waits
  3. Do not block a cooperative event loop
  4. Races and cancellation still require design
  5. Compare under explicit resource limits
  6. Ask Logeia about this articleCheck your understanding

Concurrency is not identical to parallel execution

A thread is an execution context scheduled by an operating system or another scheduler. Asynchronous processing organizes work so that other operations can progress while one completion is pending. They are not mutually exclusive choices at the same layer: an asynchronous runtime can itself use multiple threads. One thread can overlap waits for several requests without executing their CPU instructions simultaneously on multiple cores. Distinguish concurrency from parallelism before estimating throughput. An async interface can reduce the number of blocked execution contexts for an I/O-heavy workload, but its name alone does not establish more processor capacity or prove that a CPU-heavy computation will finish sooner.

AspectThreadsAsync tasks
SchedulingOS or another schedulerRuntime and actual suspension points
CPU parallelismDepends on environment and workNot guaranteed by declaring async
BoundsManage memory and connectionsManage tasks and connections

Overlap independent external waits

Consider an illustrative model with three independent external requests, each returning after 100 milliseconds. Starting the next only after the previous completes gives about 300 milliseconds of waiting. Starting all three and then awaiting completion can overlap waits and approach 100 milliseconds, subject to setup and service constraints. Either separate threads or an asynchronous design can express that overlap. If one response supplies the next request’s input, the operations are not independent. Server concurrency limits and connection capacity also matter. The numbers are not measured performance results; they isolate the effect of dependencies. Identify which waits can overlap before choosing a runtime mechanism or promising a latency reduction.

Do not block a cooperative event loop

A task running a long computation or ordinary blocking I/O on a single event-loop thread can prevent other tasks from progressing. Declaring a function async does not make every instruction preemptible. The implementation needs actual suspension through an appropriate asynchronous API or a supported way to offload blocking work. Conversely, moving work to another thread does not universally guarantee parallel CPU computation: language-runtime restrictions and the kind of work matter. Classify the wait and execution environment first. Measure event-loop delay separately from external request latency when diagnosing responsiveness, because a healthy remote service cannot compensate for a local loop that never returns control to schedule its other tasks.

Races and cancellation still require design

Threads need coordination for shared-state races, but asynchronous code also can observe changes across an await. One event-loop thread does not make an entire multi-step operation atomic. A task might check available capacity, suspend, and later consume capacity that another task used meanwhile. Timeouts and cancellation introduce resource-lifetime requirements on both approaches. Connections, files and reservations need cleanup even when work is interrupted. Requesting cancellation also does not prove that a remote side effect was undone. Specify ownership, cleanup and retry behavior rather than assuming that one concurrency style eliminates these concerns. The meaningful boundary is the operation whose consistency and completion contract the application needs to preserve.

Compare under explicit resource limits

Neither threads nor asynchronous tasks should grow without bounds. Even lightweight tasks can retain memory, connections and queued requests, while an external service has its own concurrency capacity. Set concurrency limits or bounded queues and define whether overload waits, rejects work or reduces processing. Compare approaches under the same offered load, resource limits, timeout policy and error criteria. Tail latency matters alongside a mean. Start by determining whether the workload is CPU-bound or dominated by I/O waits and what the existing libraries actually support. This provides a practical selection process without assuming that rewriting every blocking interface as async is automatically beneficial or that a fixed number of threads is universally optimal.

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Build your CS foundations · STEP 18

Understand the systems behind the web · STEP 5

Choose a learning path