This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When Python is compiled in debug mode, PyMem_Malloc() uses debug
hooks, but it also uses pymalloc allocator instead of malloc().
Problem: pymalloc is not thread-safe, whereas PyMem_Malloc() is
thread-safe in release mode (it's a thin wrapper to malloc() in this
case).
Modify the debug hook to use malloc() for PyMem_Malloc().
I wrote this PR because I used PyMem_Malloc()/PyMem_Free() in PyThread_start_new_thread() whereas PyMem_Malloc()/PyMem_Free() are not thread safe when Python is build is debug mode and I didn't know that! https://bugs.python.org/issue33015#msg330806
But I fixed PyThread_start_new_thread() using PR #10829 (commit bc9f53f). So this change is not strictly needed.
When Python is compiled in debug mode, PyMem_Malloc() uses debug
hooks, but it also uses pymalloc allocator instead of malloc().
Problem: pymalloc is not thread-safe, whereas PyMem_Malloc() is
thread-safe in release mode (it's a thin wrapper to malloc() in this
case).
Modify the debug hook to use malloc() for PyMem_Malloc().
vstinner
changed the title
[2.7] bpo-33015: Make PyMem_Malloc() thread-safe in debug mode
[2.7] bpo-35368: Make PyMem_Malloc() thread-safe in debug mode
Nov 30, 2018
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When Python is compiled in debug mode, PyMem_Malloc() uses debug
hooks, but it also uses pymalloc allocator instead of malloc().
Problem: pymalloc is not thread-safe, whereas PyMem_Malloc() is
thread-safe in release mode (it's a thin wrapper to malloc() in this
case).
Modify the debug hook to use malloc() for PyMem_Malloc().
https://bugs.python.org/issue35368