Event-Based Concurrency and Preemptive Multitasking

Stub. Event-based concurrency (a single-threaded event loop over non-blocking I/O) as an alternative to thread-based concurrency, and preemptive multitasking — how the OS forcibly regains control of the CPU from a running process/thread via timer interrupts, rather than relying on it to yield voluntarily.

· 1 min read · 149 words

Two different answers to “how do many things make progress on one CPU.” Event-based concurrency sidesteps locks and races almost entirely: a single thread runs an event loop, dispatching to a handler for whichever non-blocking I/O event is ready, so there’s never more than one handler running at once (at the cost of one blocking/slow handler stalling everything). Preemptive multitasking is the orthogonal, lower-level mechanism that makes thread-based concurrency actually work without processes cooperating: a periodic timer interrupt hands control back to the scheduler regardless of what the running code is doing, which is what turns “the OS controls the CPU” from a cooperative convention into a guarantee.

Outline (TODO — flesh out each)

  • Event-based concurrency — the event loop, non-blocking I/O
  • Why a single blocking call stalls an event-based system
  • Preemptive multitasking — timer interrupts, forced context switches

← All notes