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

idea: Joining multiple threads safely #1098

Open
shirok opened this issue Jan 11, 2025 · 0 comments
Open

idea: Joining multiple threads safely #1098

shirok opened this issue Jan 11, 2025 · 0 comments

Comments

@shirok
Copy link
Owner

shirok commented Jan 11, 2025

Recent fix in pmap brought attention to this issue.

It is a common pattern that you start multiple worker threads, and later join them all. If one of thread-join! throws an error and we don't handle it, the remaining threads are left unjonied.

So the good way is to always catch exceptions and record them from thread-join! while iterating the list of worker threads, and once all are joined, handle the recorded exceptions. We can make that pattarn an API, say, thread-join-all!.

There are several possibilities regarding how to handle the caught exceptions.

  • thread-join-all! returns a list of results, and replace the thrown condition in place of the result.
  • Reraise any one of them after all threads are joined.
  • Reraise a compond condition of all of caught exceptions.
  • Call a callback.
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

No branches or pull requests

1 participant