Skip to content
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

Type slots are not thread-safe in free-threaded builds #127266

Open
mpage opened this issue Nov 25, 2024 · 0 comments
Open

Type slots are not thread-safe in free-threaded builds #127266

mpage opened this issue Nov 25, 2024 · 0 comments
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@mpage
Copy link
Contributor

mpage commented Nov 25, 2024

Bug report

Bug description:

Modification of type slots is protected by the global type lock, however, type slots are read non-atomically without holding the type lock. For example, in PyObject_SetItem:

cpython/Objects/abstract.c

Lines 231 to 235 in 5bb059f

if (m && m->mp_ass_subscript) {
int res = m->mp_ass_subscript(o, key, value);
assert(_Py_CheckSlotResult(o, "__setitem__", res >= 0));
return res;
}

It's not clear how we want to address this. From @colesbury in #127169 (comment):

I'd lean towards doing a stop-the-world pause when modifying the slot so that we don't need 
to change every read. I expect that to be a bit tricky since class definitions look like they're mutating 
the class.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

@mpage mpage added type-bug An unexpected behavior, bug, or error 3.13 bugs and security fixes topic-free-threading 3.14 new features, bugs and security fixes labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant