GIL's Core Purpose: Safeguarding Reference Counts

The GIL primarily protects CPython's reference counting mechanism, preventing race conditions where multiple threads simultaneously modify an object's `ob_refcnt`, which could lead to memory leaks or crashes.

Sources

Open the full topic