This came up in another thread (sic) -- I don't see any way to wait for one thread out of N to finish (except maybe spawning N more threads that call
join on the original ones and send the results over a channel type that supports
This is not possible on Linux at least. On Windows it might be possible with WaitForMultipleObjects, but even then you're limited to 64 objects. Using
select and channels is the only portable way.
I see, thanks
You can do it in application code: Add a guard in each thread, which signals a shared object (e.g. a condition variable, channel, manualresetevent, etc). Then wait on that object.
If you need to be sure that the thread is really joined and not only close to being joined, then you need to pass each thread some unique ID that you can send back via this channel. Then the waiter can identify the associated
JoinHandle and join the thread.