Skip to content

Make random.Random thread-safe in --disable-gil builds #112071

@colesbury

Description

@colesbury

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:

  1. No need for an extra _PyMutex mutex in RandomObject
  2. 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.
  3. Compared to nogil-3.12, we want to push the locking "up" to the around the methods. (See the above note 2).

Linked PRs

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy