Closed
Description
The next_version_tag in typeobject.c is currently not thread safe and relies on GIL to protect against concurrent increments across threads.
Lines 46 to 50 in 63140b4
For per-interpreter GIL, it must be made thread-safe otherwise the type cache will be affected by race conditions. Static types are not affected because they are immutable so this is a issue for pure Python classes aka heap types. This issue is for discussion of possible implementations.
Possible Solutions:
- Make the
next_version_tagcounter per interpreter, while this may seems to fix the issue but since objects are shared across the interpreters and the type version tag is also used to represent a current state of a type in the specializing interpreter, two interpreters can have same the same tag for different types this won't work as expected. - Make the
next_version_tagan atomic counter and increment it atomically using thepyatomic APIs. This is my preferred solution sincenext_version_tagis only modified when a type is modified so is a rare operation and not a performance issue. Since this is just a counterrelaxed orderingcan be used here.
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
Done