Concurrency: an introduction

A thread is another point of execution inside a single process: its own program counter, its own registers and its own stack, but the same address space as every other thread in the program. The tabs below follow OSTEP Chapter 26, from what a second stack looks like to why a shared counter ends up with the wrong value.

A thread's stack

what has to be private when everything else is shared


    

The address space

A 16KB address space, drawn as in the chapter. Code and heap are shared by every thread; each stack belongs to one thread alone.

  • shared
  • thread 1 only
  • thread 2 only
  • thread 3 only

How many threads

Every thread the program creates needs a stack of its own somewhere in the space.

Private and shared

The OS keeps one thread control block per thread, much as it keeps a process control block per process. Switching between threads of the same process leaves the address space, and so the page table, untouched.

Keyboard: ← → to step, Space to play or pause.

Program, traces and the counter example follow OSTEP, Chapter 26, Concurrency: An Introduction.