-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add PyMutex, PyMutex_Lock, PyMutex_Unlock #142
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
Comments
I think backporting PyMutex would be nontrivial, since it relies on integration with mimalloc AIUI. Instead, you could follow what we did in NumPy and explicitly wrap PyThread_type_lock and PyMutex in a compatibility macro, or similar. numpy/numpy#27011 I'm not sure if it makes sense to put something like that in pythoncapi-compat. |
I was hopping that it would have been possible to have a generic way to implement it here, maybe using But after playing for a while with your suggestion (which was also Emma's), I'm starting to wonder if it's possible at all, as But my knowledge about both C and the CPython C API is limited, so I would be happy if someone proves me wrong! In the meanwhile, I will work following the suggestion previously mentioned. Thanks! |
PyMutex doesn't need to be heap-allocated, so you can leave the allocate and free functions as stubs. The docs for PyMutex say you need to initialize like it like e.g.
But that's the only special thing you need to handle. |
Sorry, I was not clear at all in my last message. I was thinking if it was possible, as a compatibility layer to Like you mentioned, since the initialization of Likewise for calling |
Couldn't the compat function just not do anything to allocate and free the object in the For example, in There's a similar ifdef in Does that make sense? |
Backporting the whole feature to Python 3.12 would be too much work (add too much code, complicated to maintain). I suggest closing this issue. You have to add two different code paths depending on the Python version: By the way, I'm working on python/cpython#134747 : "Change PyThread_allocate_lock() implementation to PyMutex" on Python 3.15 :-) |
I understand that backporting Thank you for the pointers! |
Hello, I am doing a backport of code using
PyMutex
/PyMutex_Lock
/PyMutex_Unlock
. Could it be possible to add them to this repository?References:
The text was updated successfully, but these errors were encountered: