Skip to content
Prev Previous commit
Next Next commit
Wait for all the threads to finalize.
  • Loading branch information
ericsnowcurrently committed May 16, 2023
commit 54dc3b5f299208d886edb2dfaff23aaea449203f
9 changes: 9 additions & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ module_threads_reinit(struct module_threads *threads)
static void
module_threads_fini(struct module_threads *threads)
{
// Wait for all the threads to finalize.
PyThread_acquire_lock(threads->mutex, WAIT_LOCK);
while (threads->head != NULL) {
PyThread_release_lock(threads->mutex);
// XXX Sleep?
PyThread_acquire_lock(threads->mutex, WAIT_LOCK);
}
PyThread_release_lock(threads->mutex);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this doesn't feel right. I'm going to look at what my options are. A condvar would work, but that doesn't seem to be something we do in CPython outside the GIL.

(I'm also open to ideas.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've come up with a slightly better approach.


PyThread_free_lock(threads->mutex);
}

Expand Down