Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Dec 3, 2018

Add "assert(PyGILState_Check());" assertion to pymalloc functions
like pymalloc_alloc() to ensure that the GIL is held.

Remove also _PyGILState_check_enabled define: use directly
_PyRuntime.gilstate.check_enabled.

Note: The debug hook already uses _PyMem_DebugCheckGIL() to check
that the GIL is held.

https://bugs.python.org/issue35368

Add "assert(PyGILState_Check());" assertion to pymalloc functions
like pymalloc_alloc() to ensure that the GIL is held.

Remove also _PyGILState_check_enabled define: use directly
_PyRuntime.gilstate.check_enabled.

Note: The debug hook already uses _PyMem_DebugCheckGIL() to check
that the GIL is held.
@vstinner
Copy link
Member Author

vstinner commented Dec 3, 2018

This change is not really a bugfix. If Python is compiled in debug mode, debug hooks are installed by default and so _PyMem_DebugCheckGIL() is checked by each PyMem_Malloc() and PyObject_Malloc() call.

This change only impacts PYTHONMALLOC=pymalloc case on Python compiled in debug mode.

The assertion is more here as a "documentation" that pymalloc is not thread-safe (currently).

@vstinner
Copy link
Member Author

This change is not really a bugfix. If Python is compiled in debug mode, debug hooks are installed by default and so _PyMem_DebugCheckGIL() is checked by each PyMem_Malloc() and PyObject_Malloc() call.

This PR adds an overhead at runtime for little benefit, so I abandon my PR.

@vstinner vstinner closed this Dec 18, 2018
@vstinner vstinner deleted the pymalloc_gil branch December 18, 2018 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants