Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
code review: make exiting thread safe
  • Loading branch information
kumaraditya303 committed Dec 22, 2025
commit cc959daa04337b5433c22563d8bb95aa6023c17d
8 changes: 2 additions & 6 deletions Python/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
{
ENSURE_Context(octx, -1)
PyContext *ctx = (PyContext *)octx;
#ifdef Py_GIL_DISABLED
int already_entered = _Py_atomic_exchange_int(&ctx->ctx_entered, 0);
#else
int already_entered = ctx->ctx_entered;
ctx->ctx_entered = 0;
#endif
int already_entered = FT_ATOMIC_LOAD_INT_RELAXED(ctx->ctx_entered);

if (!already_entered) {
PyErr_Format(PyExc_RuntimeError,
Expand All @@ -253,6 +248,7 @@ _PyContext_Exit(PyThreadState *ts, PyObject *octx)
Py_SETREF(ts->context, (PyObject *)ctx->ctx_prev);

ctx->ctx_prev = NULL;
FT_ATOMIC_STORE_INT(ctx->ctx_entered, 0);
context_switched(ts);
return 0;
}
Expand Down