Skip to content

Commit

Permalink
Don't need atomics in dtor
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Feb 13, 2024
1 parent 9d35990 commit e554c5e
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,6 @@ new_thread_handle(thread_module_state* state)
return self;
}

static int
detach_thread(ThreadHandleObject *handle)
{
assert(get_thread_handle_state(handle) == THREAD_HANDLE_RUNNING);

// This is typically short so no need to release the GIL
if (PyThread_detach_thread(handle->handle)) {
PyErr_SetString(ThreadError, "Failed detaching thread");
return -1;
}
set_thread_handle_state(handle, THREAD_HANDLE_DETACHED);
return 0;
}

static void
ThreadHandle_dealloc(ThreadHandleObject *self)
{
Expand All @@ -144,10 +130,15 @@ ThreadHandle_dealloc(ThreadHandleObject *self)
}
HEAD_UNLOCK(&_PyRuntime);

if (get_thread_handle_state(self) != THREAD_HANDLE_INVALID &&
_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)detach_thread,
self) == -1) {
PyErr_WriteUnraisable(tp);
if (self->state == THREAD_HANDLE_RUNNING) {
// This is typically short so no need to release the GIL
if (PyThread_detach_thread(self->handle)) {
PyErr_SetString(ThreadError, "Failed detaching thread");
PyErr_WriteUnraisable(tp);
}
else {
self->state = THREAD_HANDLE_DETACHED;
}
}
_PyEventRc_Decref(self->thread_is_exiting);
PyObject_Free(self);
Expand Down

0 comments on commit e554c5e

Please sign in to comment.