Detect if any of several thread finishes or panics early?
⚓ Rust 📅 2026-03-09 👤 surdeus 👁️ 2I have a handful of threads doing things for a program. All are critical, and none are expected to exit on their own. What's the most correct/safe/ergonomic way to detect if one of them has finished early, and propagate a panic if one of them has panicked?
Things I've considered:
- Looping and
try_join-ing the join handles in sequence. Would probably work, but the loop strikes me as not the correct answer because of all the polling. - Thread scopes. Initially promising on the panic angle at least, but then I realized the scope only panics when ALL the contained threads have joined.
- Async with Tokio. Make each thread a blocking Task, then do a
select!or use aJoinSet. Best result I've found yet. Mirrors what Nextest does. But apparently, blocking tasks aren't meant to be equivalent to threads, and should only be used for short-running things.
Currently leaning to the Async with Tokio approach, but I have my doubts. Anyone willing to chip in their two cents?
1 post - 1 participant
🏷️ Rust_feed