| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This would need a fair amount of work before it's ready to merge:
GH-155882 fixes the missing atomics on the export increments but doesn't fix the last issue. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
As reported in #127716, on no-gil build, several threads calling memoryview.release() on views of the same buffer will cause problem.
Root cause
Let's take a look at memoryview.release()
Here "test the flag" (1) and "set the flag" (2) are two separate, unsynchronized operations. When mbuf->exports == 1, two threads race like this:
Both threads get past the guard, so both run the decrement. As a result, mbuf->exports drops below 0.
Fix
To fix this, we have to make self->flags's test-and-set a single atomic operation, so that exactly one thread wins the transition and performs the decrement. Here I'm using _Py_atomic_or_uint32. It is used in both release entry points:
Testing