-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-125053: Document that ob_mutex must only be used via critical section API #144599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0d37059 to
c1f0568
Compare
…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.
c1f0568 to
8c202f0
Compare
|
Hello, hope this works, claiming this issue. Thanks! |
| :c:type:`PyMutex` is very lightweight — it is only one byte — so there is | ||
| negligible cost to having an additional one:: | ||
|
|
||
| /* WRONG — do not lock ob_mutex directly */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the example is needed, the explanation text seems sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the code example.
Summary
ob_mutex)" subsection to the free-threading extensions howto (Doc/howto/free-threading-extensions.rst) warning thatob_mutexis reserved for the critical section API and must not be locked directly withPyMutex_Lockob_mutexmember entry underPyObjectin the C API reference (Doc/c-api/structures.rst) with a cross-reference to the howtoInclude code examples showing wrong (direct lock) vs. right (critical section or separate mutex) approachesCloses #125053
Test plan
make htmlinDoc/builds with no warningsstructures.htmltofree-threading-extensions.html#per-object-locksrenders correctlyInclude/object.h,Include/cpython/pylock.h,Include/internal/pycore_critical_section.h)ob_mutexshould only be used with the critical section API #125053📚 Documentation preview 📚: https://cpython-previews--144599.org.readthedocs.build/