封装一个自动join()的RAII线程类是否能提高异常安全性,避免其它一些问题?
firma2021 opened this issue · comments
类似于
class scoped_thread
{
private:
thread thread_;
public:
template <typename... Arg>
scoped_thread(Arg&&... arg)
: thread_(std::forward<Arg>(arg)...)
{}
scoped_thread(scoped_thread&& other)
: thread_(std::move(other.thread_))
{}
scoped_thread(const scoped_thread&) = delete;
~scoped_thread()
{
if (thread_.joinable())
{
thread_.join();
}
}
};
我觉得不错,你可以推一个分支进来哦,一起参与进来。
好的!