Feature or enhancement
random.Random has mutable internal state. We should use the critical section API to make it thread-safe in --disable-gil builds.
For context, here is the change from the nogil-3.12 fork. colesbury/nogil-3.12@9bf62ffc4b. Note that we want to do things a bit differently in CPython 3.13:
- No need for an extra
_PyMutex mutex in RandomObject
- Use the critical section API. Locking can be added around operations that use Argument Clinic by adding the
@critical_section directive as the first line.
- Compared to
nogil-3.12, we want to push the locking "up" to the around the methods. (See the above note 2).
Linked PRs
Feature or enhancement
random.Randomhas mutable internal state. We should use the critical section API to make it thread-safe in--disable-gilbuilds.For context, here is the change from the
nogil-3.12fork. colesbury/nogil-3.12@9bf62ffc4b. Note that we want to do things a bit differently in CPython 3.13:_PyMutex mutexinRandomObject@critical_sectiondirective as the first line.nogil-3.12, we want to push the locking "up" to the around the methods. (See the above note 2).Linked PRs
_random.Randommethods thread-safe in--disable-gilbuilds #112128