Skip to content

gh-129824: fix data races in subinterpreters under TSAN #135794

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jun 21, 2025

This fixes the data races in typeobject.c in subinterpreters under free-threading. The type flags are only modified in the main interpreter as all static types are first initialized in main interpreter. With the fix the test_interpreter_pool tests have no data races in typeobject.c under TSAN (there are still some unrelated data races in module exec like posix and struct).

@kumaraditya303 kumaraditya303 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 23, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit be846e8 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135794%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 23, 2025
@kumaraditya303
Copy link
Contributor Author

kumaraditya303 commented Jun 25, 2025

This also fixes #116909 so more of test_capi tests can be enabled under free-threading TSAN (will do in follow up).

@@ -1359,6 +1358,19 @@ _PyType_LookupByVersion(unsigned int version)
#error "_Py_ATTR_CACHE_UNUSED must be bigger than max"
#endif

static inline unsigned int
get_next_global_version_tag(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call this something like "next_global_version_tag(void)" instead of "get_next_global_version_tag".

"get_" makes it sound like a function that retrieves the next version tag without modifying it.

do {
old = _Py_atomic_load_uint_relaxed(&_PyRuntime.types.next_version_tag);
if (old >= _Py_MAX_GLOBAL_TYPE_VERSION_TAG) {
return (unsigned int)-1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 0 for an invalid version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants