I know I can call thread.join() to force a thread to complete before the current thread can proceed. However, my program has a bunch of files that are read into memory, modified, and then flushed to disk. Each flush is being done in a separate thread so that the current thread can continue while the contents are flushed to disk.
I could keep a set of all spawned threads and then join them all at the end of the main thread's execution, but if the program runs for a long time there could be a huge number of flush-threads, most of which completed anyway.
Is there any way to join all active threads before proceeding and exiting the main thread?