Wait for threads to stop.