Visitar URL original
gh-104341: Minor Fixes in the _thread Module by ericsnowcurrently · Pull Request #104595 · python/cpython · GitHub
Skip to content
Draft
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
Fix untrack_module_thread().
  • Loading branch information
ericsnowcurrently committed May 18, 2023
commit a44c03f4f8662a5cd6bd85cb7b62d6d1354ab7a6
10 changes: 5 additions & 5 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,18 @@ release_module_thread_tstate(struct module_threads *threads,
}

static void
finalize_module_thread(struct module_threads *threads,
untrack_module_thread(struct module_threads *threads,
struct module_thread *mt)
{
assert(_PyThreadState_GET() == NULL);

PyThread_acquire_lock(threads->mutex, WAIT_LOCK);

assert(mt->tstate == _PyThreadState_GET());
assert(mt->status.func_ended);
assert(mt->status.tstate_cleared);
threads->counts.running--;

PyThread_release_lock(threads->mutex);

delete_module_thread(mt);
}


Expand Down Expand Up @@ -1318,7 +1317,8 @@ thread_run(void *boot_raw)
Py_DECREF(pyargs);
Py_XDECREF(pykwargs);
release_module_thread_tstate(threads, mt);
finalize_module_thread(threads, mt);
untrack_module_thread(threads, mt);
delete_module_thread(mt);

// bpo-44434: Don't call explicitly PyThread_exit_thread(). On Linux with
// the glibc, pthread_exit() can abort the whole process if dlopen() fails
Expand Down