posted on 2025-05-01, 00:00authored byAli Siddiqui
CPython's Global Interpreter Lock (GIL) has been a long-standing performance bottleneck for the Python programming language, forcing Python threads to run one at a time and preventing real shared memory parallelism in Python programs. Recently, the Python Steering Council has accepted a proposal to eliminate the GIL and bring real multithreading to CPython for the first time. An experimental "free-threaded" version of CPython implementing this proposal is now being actively developed by the core CPython team. In this thesis, we explore the consequences of removing the GIL on CPython's memory model, the semantics it guarantees to multithreaded programs. We argue that CPython has historically provided an extremely strong memory model, sequential consistency, to Python programs, and that without careful implementation of free-threading, this may no longer be the case. We characterize the memory model of free-threaded CPython using litmus tests, small concurrent programs that expose violations of sequential consistency, and we aim to explain our results using measurements collected from analogous litmus tests in lower-level languages and hardware performance counters. We also use a simple form of mutation testing to validate that our litmus testing strategy can effectively detect sequential consistency violations in CPython's free-threaded implementation.