liveBook · Manning

Execution context

As explained in Grokking Concurrency

The collection of program state, executable instructions, memory, and resources associated with a running process.

Think of an execution context as the information needed to pause a running task and pick it up again. For a process, that includes its executable, address space, and resources such as open files and network connections. section 4.3

For a task running on a processor, the context also includes its current instruction position and CPU state, such as flags and registers. The operating system saves this state before switching to another task and restores it when the first task resumes. section 6.9

Processes and threads are related but distinct: a process has at least one thread, and each thread maintains an independent execution context. Starting a process is heavyweight because it brings together many kinds of state and resources. section 4.3 section 4.6

Returning to a conversation

If a phone call interrupts a conversation, you switch contexts: you attend to the caller, then return to the earlier conversation. A processor similarly saves one task’s context and restores it so the task can continue where it left off. The switch takes time and system resources. section 6.9

How Grokking Concurrency covers it

How deep it goes
Defines process and task context, then outlines saving and restoring state without detailing implementation.
Examples
Uses an interrupted phone conversation to illustrate switching contexts and returning to prior work.
What you can do after
Understand what state the operating system must save and restore when switching tasks.
How it connects
Connects execution context to processes, threads, context switching, and multitasking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.