Use case for std::promise::set_{value|exception}_at_thread_e

Use case for std::promise::set_{value|exception}_at_thread_exit

本文关键字:exception at thread value case std promise set Use for      更新时间:2023-10-16

我什么时候必须使用std::promise::set_value_at_thread_exit/std::promise::set_exception_at_thread_exit而不是std::promise::set_value/std::promise::set_exception

唯一的区别是,前者保证仅在调用线程的thread_local被销毁后才使关联的未来准备就绪。但是,我想不出任何非合成示例会很有用。

一件事可能是知道一个分离的线程是否已经完成运行,当你的程序仍然处于它关心知道的状态时。