wait for thread to finish