I have function foo:
void foo(){
//Command set A
std::this_thread::sleep_for(100s);
//Command set B
}
The first part which is Command set A
has to block the execution. However, the sleep
part and //Command set B
does not have to block the execution and does not return any data.
So I implement it as follow:
void foo(){
//Command set A
std::thread t([](){
std::this_thread::sleep_for(100s);
//Command set B
}
t.detach()
}
Did I utilizedetach
correctly here? Is it the right place to use detach
? is there a better solution?