c++ 退出detach的线程

给线程传个参数

std::reference_wrapper<bool> p_quit

接着线程里判断是否退出。

bool b = false;
thread t1(func1,arg1,std::ref(b));
void funct1(arg1, std::reference_wrapper<bool> p_quit) {
    while (true) {
        if (p_quit) break;
    }
}