waiting for the finalization of a thread