Skip to content

multithreading

Multithreading is a concurrency model in which a single process runs multiple threads of execution that share the same memory space:

A teal process box fans out to three thread boxes, each labeled with its own stack, and all three point down to one yellow box holding the shared heap and globals.
Every thread keeps its own stack, but they all read and write one shared memory space.

Each thread keeps its own program counter and call stack, but every thread in the process reads and writes the same heap and global data. The operating system’s scheduler interleaves the threads on a single core, switching rapidly between them, or runs them at the same time across several cores. Multithreading can therefore deliver concurrency, parallelism, or both.

Programs turn to multithreading to stay responsive while waiting on input and output, and to spread computation across cores. Shared memory makes communication between threads cheap, but it also invites race conditions when two threads update the same data at once.

Code that behaves correctly under any interleaving is called thread-safe, and multithreaded programs reach that state by guarding shared data with synchronization primitives such as mutexes and semaphores. Creating a fresh thread for every task is costly, so work is often handed to a fixed group of reusable threads called a thread pool.

In Python, the threading module exposes this model, although CPython’s global interpreter lock (GIL) has long allowed only one thread to execute Python bytecode at a time. Free-threaded builds, introduced as an experimental option in Python 3.13 and officially supported in Python 3.14, relax that limit.

An Intro to Threading in Python

Tutorial

An Intro to Threading in Python

In this intermediate-level tutorial, you'll learn how to use threading in your Python programs. You'll see how to create threads, how to coordinate and synchronize them, and how to handle common problems that arise in threading.

intermediate best-practices

For additional information on related topics, take a look at the following resources:


By Martin Breuss • Updated Sept. 5, 2026