← Lessons

quiz vs the machine

Gold1440

Concurrency

The Preemption Points

Where a runtime is allowed to forcibly pause a task so others get a turn.

5 min read · core · beat Gold to climb

Forcing a fair turn

Pure cooperation breaks when a task refuses to yield. Preemption is the runtime's power to pause a task even when it did not ask to stop. A preemption point is a place where that interruption is allowed to happen safely.

Why points are needed

You cannot pause a task at literally any instruction, because its data might be half updated. Instead the runtime defines safe spots:

  • Function call boundaries, where the runtime can insert a quick check.
  • Loop back edges, so a long loop is interrupted between iterations.
  • Allocation or await points, which the task already passes through often.

At each point the runtime checks a flag. If the task has run too long, it yields control to the scheduler so other tasks can run.

Cooperative versus forced

Some runtimes rely only on these inserted checks, a style called cooperative preemption. Others use a timer signal to interrupt a thread directly, giving truly forced preemption at the cost of more complexity and care around safe points.

Key idea

Preemption points are safe spots like loop edges and calls where a runtime can check a flag and pause a long running task, giving fairness without interrupting in the middle of an unsafe operation.

Check yourself

Answer to earn rating on the learn ladder.

1. Why can a task not be preempted at any instruction?

2. Which of these is a common preemption point?

3. What is cooperative preemption?