类似lockguard的一个自定义的类,可以在线程退出的时候,将内容进行习销毁操作。(调用joinable和join方法)
方法:
class thread_guard
{
thread &t;
public:
explicit thread_guard(thread& _t) :
t(_t){}
~thread_guard()
{
if (t.joinable())
t.join();
}
thread_guard(const thread_guard&) = delete;
thread_guard& operator=(const thread_guard&) = delete;
};