Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@mpage

Description

@mpage
Issue body actions

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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.