wait for all threads ended then exit