Skip to content

docs: ob_mutex should only be used with the critical section API #125053

Closed

Description

@colesbury

The ob_mutex field in the experimental free threading build should only be used by the critical section API. It should not be locked directly (i.e., no PyMutex_Lock(&obj->ob_mutex)).

It's not safe to lock the same mutex using the critical section API and the plain mutex API because it may deadlock. Even if you never use the critical section API on instances of your type, it's possible that other code uses the critical section API on generic Python objects.

PyMutex objects are cheap -- just add a new one to your object if necessary.

We should document this somewhere.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Feb 8, 2026
  2. added a commit that references this issue on Mar 10, 2026
  3. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions