main(){
std::thread thread_pulse([=]{
*this->do_adress = true;
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
*this->do_adress = false;
//delete this thread to avoid memory leaks
});
//do some other stuff without waiting for the thread to terminate
}
をどのように私は、スレッドの実行が行われたときに、スレッドが削除されたことを保証しないと何もありませんスレッドがメインで実行を終了するのを待たずにメモリリークが発生する?
EDIT:助けを
おかげで、あなたはあなたがから戻る前に、あなたは右クリックmain
を終了する前に必ずスレッドが実行されるようにしたい場合は、私は
main(){
std::thread ([=]{
*this->do_adress = true;
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
*this->do_adress = false;
//delete this thread to avoid memory leaks
}).detach;
//do some other stuff without waiting for the thread to terminate
}
'std :: thread thread_pulse(...); thread_pulse.detach(); ' –