Content-Length: 288466 | pFad | https://github.com/python/cpython/issues/155519

ad Data race with Context ctx_vars under free-threading · Issue #155519 · python/cpython · GitHub
Skip to content

Data race with Context ctx_vars under free-threading #155519

Description

@nascheme

Bug report

Bug description:

The HAMT held by a context is immutable, but the pointer to it is not: contextvar_set() and contextvar_del() install a new HAMT and drop the reference to the previous one. Only the thread that entered a context can do that (a context cannot be entered by two threads at once), but any thread can read a context object at any time -- ctx.copy(), len(ctx), ctx.items(), etc. Such a reader has to acquire its own reference to the HAMT under the context's lock; reading ctx_vars unlocked lets the writer deallocate the HAMT while the reader is walking it.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/155519

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy