Global interpreter lock¶
Category: Parallelism · Status: stub · Lessons: chapter 07, Parallelism
One line: A lock that lets only one thread run interpreter code at a time — CPython's, and Ruby's — so threads give concurrency but not CPU parallelism; CPython 3.13 added an optional build without it.
Also called: GIL, GVL, free threading.
How it connects¶
flowchart LR
n_gil["Global interpreter lock"]
n_mutex["Mutex"]
n_gil -->|uses| n_mutex
classDef center stroke-width:3px
class n_gil center
classDef outside stroke-dasharray: 4 3
class n_mutex outside
- Is built on: Mutex
- See also: I/O-bound and CPU-bound work, Multiprocessing
In each language¶
| Python | CPython's GIL ↗; the free-threaded build ↗, available since 3.13, disables it |
| Elsewhere | CRuby holds its Global VM Lock (GVL) per Ractor ↗, so ractors run in parallel where threads cannot |
Where to read more¶
- In the books: Python Concurrency with asyncio, Matthew Fowler — ch. 1, 'Getting to know asyncio' → 'Understanding the global interpreter lock'
- In the books: Parallel Programming with Python, Jan Palach — ch. 1, 'Contextualizing Parallel, Concurrent, and Distributed Programming' → 'Taking care of Python GIL'
- In the books: Advanced Python Programming, Quan Nguyen — ch. 15, 'The Global Interpreter Lock'
- In the books: Fluent Python, Luciano Ramalho — ch. 19, 'Concurrency Models in Python' → 'The Real Impact of the GIL'
- In the books: Python Cookbook, David Beazley, Brian K. Jones — ch. 12, 'Concurrency' → 'Dealing with the GIL (and How to Stop Worrying About It)'
- Reference: PEP 703: Making the Global Interpreter Lock Optional in CPython ↗