How to check whether std::thread ended?