GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ensure current thread state is cleared before deleting it in _PyThreadState_DeleteCurrent · Issue #116515 · python/cpython

Ensure current thread state is cleared before deleting it in _PyThreadState_DeleteCurrent #116515

New issue
Copy link
New issue
Copy link
Closed
Closed
Ensure current thread state is cleared before deleting it in _PyThreadState_DeleteCurrent#116515
Copy link
Assignees
colesbury
Labels
topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Mar 8, 2024
Issue body actions

Feature or enhancement

In general, when _PyThreadState_GET() is non-NULL then the current thread is "attached", but there is a small window during PyThreadState_DeleteCurrent() where that's not true: tstate_delete_common() is called when the thread is detached, but before current_fast_clear():

cpython/Python/pystate.c

Lines 1689 to 1691 in 601f3a7

tstate_set_detached(tstate, _Py_THREAD_DETACHED);
tstate_delete_common(tstate);
current_fast_clear(tstate->interp->runtime);

I think it's worth swapping the order of the calls so that we call current_fast_clear before tstate_delete_common. This would also make the order of operations in PyThreadState_DeleteCurrent() more similar to the order used when calling PyThreadState_Delete().

See also: #116483

cc @ericsnowcurrently

Linked PRs

  • gh-116515: Clear thread-local state before tstate_delete_common() #116517
Reacted by Eric Snow

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 8, 2024
  2. colesbury
    self-assigned this
    on Mar 8, 2024
  3. colesbury
    added
    topic-C-API
    on Mar 8, 2024
  4. colesbury
    added 2 commits that reference this issue on Mar 8, 2024

    pythongh-116515: Clear thread-local state before tstate_delete_common()

    4f541ef

    gh-116515: Clear thread-local state before tstate_delete_common() (#1…

    9f983e0
  5. colesbury
    closed this as completedon Mar 11, 2024
  6. adorilson
    added a commit that references this issue on Mar 25, 2024

    pythongh-116515: Clear thread-local state before tstate_delete_common…

    9052a2f
  7. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-116515: Clear thread-local state before tstate_delete_common…

    c1d49c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

Labels

topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.