What's the situation with PyBuffer::as_slice, ReadOnlyCell, Python::detach, and freethreaded builds? #5508
Unanswered
oconnor663
asked this question in
Questions
Replies: 1 comment 1 reply
-
|
No, dataraces are an issue even without free threading: https://alexgaynor.net/2022/oct/23/buffers-on-the-edge/ |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As I understand it, the
PyBuffer::as_slicemethod returns&[ReadOnlyCell<T>]mainly to reflect the fact that the current thread could modify the slice through an alias (or just by executing arbitrary Python code). Since&[ReadOnlyCell<T>]is notSend(becauseReadOnlyCellis notSync), we can't pass that type to aPython::detachclosure, so we don't have to worry about other threads doing the same thing and provoking a true data race... (Edit: @alex points out below that we've always had to worry about other threads usingunsafecode or just C code to do this.)...except that on freethreaded builds we do have to worry about that, right, whether or not we call
detach? I could have this wrong, but it seems to me like at least on freethreaded builds,PyBuffer::as_sliceis morally similar tomemmap2::Mmap::map, in that it is fundamentally impossible to wrap these functions in a safe API, and you ultimately have to trust the caller not to give these "weird" slices to callers that "care" about the difference. (Where "caring" about the difference is a nebulous, dangerous concept that goes against the grain of all the relevant memory models and standards?)What's the current thinking on this question, particularly for freethreaded Python? Are there any other discussions I might've missed besides #2824 ?
(The context that got me thinking about this recently is oconnor663/blake3-py#89.)
Beta Was this translation helpful? Give feedback.
All reactions