Adding wait for thread with timeout