wait for threads to finish in a ruby way