Skip to content

Conversation

@overlorde
Copy link

@overlorde overlorde commented Feb 8, 2026

Summary

  • Add a new "Per-Object Locks (ob_mutex)" subsection to the free-threading extensions howto (Doc/howto/free-threading-extensions.rst) warning that ob_mutex is reserved for the critical section API and must not be locked directly with PyMutex_Lock
  • Add an ob_mutex member entry under PyObject in the C API reference (Doc/c-api/structures.rst) with a cross-reference to the howto
  • Include code examples showing wrong (direct lock) vs. right (critical section or separate mutex) approaches

Closes #125053

Test plan

  • make html in Doc/ builds with no warnings
  • Cross-reference from structures.html to free-threading-extensions.html#per-object-locks renders correctly
  • All technical claims verified against C headers (Include/object.h, Include/cpython/pylock.h, Include/internal/pycore_critical_section.h)

📚 Documentation preview 📚: https://cpython-previews--144599.org.readthedocs.build/

@python-cla-bot
Copy link

python-cla-bot bot commented Feb 8, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

…l section API

Add a warning in the free-threading extensions howto explaining that
PyObject.ob_mutex is reserved for the critical section API and must not
be locked directly with PyMutex_Lock, as this can cause deadlocks.
Extension authors who need their own lock should add a separate PyMutex
field to their object struct.

Also add an ob_mutex member entry under PyObject in the C API reference
(Doc/c-api/structures.rst) with a cross-reference to the howto.
@overlorde overlorde force-pushed the doc-ob-mutex-warning branch from c1f0568 to 8c202f0 Compare February 8, 2026 17:04
@overlorde
Copy link
Author

Hello, hope this works, claiming this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

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

1 participant