[2.7] bpo-35368: Make PyMem_Malloc() thread-safe in debug mode#10828
[2.7] bpo-35368: Make PyMem_Malloc() thread-safe in debug mode#10828vstinner merged 1 commit intopython:2.7from vstinner:pymem_threadsafe
Conversation
|
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! But I fixed PyThread_start_new_thread() using PR #10829 (commit bc9f53f). So this change is not strictly needed. @serhiy-storchaka, @benjaminp: Is it too late to fix PyMem_Malloc() to make it thread-safe in Python 2.7? |
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 created a new issue for this change, as asked by @gpshead: https://bugs.python.org/issue35368 |
benjaminp
left a comment
There was a problem hiding this comment.
Debug mode changes are probably okay.
|
Thanks for the review @benjaminp! Hopefully, I don't think that anyone uses PyMem_Malloc() without holding the GIL in Python 2 ;-) |
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