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

bpo-39877: Fix PyEval_RestoreThread() for daemon threads (GH-18811) #313

Merged
merged 1 commit into from
Mar 8, 2020

Conversation

sthagen
Copy link
Owner

@sthagen sthagen commented Mar 8, 2020

  • exit_thread_if_finalizing() does now access directly _PyRuntime
    variable, rather than using tstate->interp->runtime since tstate
    can be a dangling pointer after Py_Finalize() has been called.
  • exit_thread_if_finalizing() is now called before calling
    take_gil(). _PyRuntime.finalizing is an atomic variable,
    we don't need to hold the GIL to access it.
  • Add ensure_tstate_not_null() function to check that tstate is not
    NULL at runtime. Check tstate earlier. take_gil() does not longer
    check if tstate is NULL.

Cleanup:

  • PyEval_RestoreThread() no longer saves/restores errno: it's already
    done inside take_gil().
  • PyEval_AcquireLock(), PyEval_AcquireThread(),
    PyEval_RestoreThread() and _PyEval_EvalFrameDefault() now check if
    tstate is valid with the new is_tstate_valid() function which uses
    _PyMem_IsPtrFreed().

* exit_thread_if_finalizing() does now access directly _PyRuntime
  variable, rather than using tstate->interp->runtime since tstate
  can be a dangling pointer after Py_Finalize() has been called.
* exit_thread_if_finalizing() is now called *before* calling
  take_gil(). _PyRuntime.finalizing is an atomic variable,
  we don't need to hold the GIL to access it.
* Add ensure_tstate_not_null() function to check that tstate is not
  NULL at runtime. Check tstate earlier. take_gil() does not longer
  check if tstate is NULL.

Cleanup:

* PyEval_RestoreThread() no longer saves/restores errno: it's already
  done inside take_gil().
* PyEval_AcquireLock(), PyEval_AcquireThread(),
  PyEval_RestoreThread() and _PyEval_EvalFrameDefault() now check if
  tstate is valid with the new is_tstate_valid() function which uses
  _PyMem_IsPtrFreed().
@sthagen sthagen merged commit febde1a into sthagen:master Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants