-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Description
Bug report
Bug description:
The PyCapsule object is not thread-safe. For example the read and write operations to the underlying pointer do not use atomics.
Line 111 in e094544
| return capsule->pointer; |
This can be fixed with atomic read and write operations. (same for the name field and some others)
Another potential issue is that some operations on a capsule are not atomic. For example a thread can attempt to retrieve a pointer using PyCapsule_GetPointer while a concurrent thread is updating the name and pointer using PyCapsule_SetName and PyCapsule_SetPointer. That could be addressed with locks, but I suspect that is too heavy for the capsule object.
I am leaning towards adding atomics for the read and write operations and documenting that in a PyCapsule does not guarantee its methods are atomic.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows