A volte devo usare std::threadper velocizzare la mia applicazione. So anche che join()aspetta che un thread sia completato. È facile da capire, ma qual è la differenza tra chiamare detach()e non chiamarlo?
Ho pensato che senza detach(), il metodo del thread funzionerà usando un thread in modo indipendente.
Non staccare:
void Someclass::Somefunction() {
//...
std::thread t([ ] {
printf("thread called without detach");
});
//some code here
}
Chiamata con distacco:
void Someclass::Somefunction() {
//...
std::thread t([ ] {
printf("thread called with detach");
});
t.detach();
//some code here
}
stde boostthread hanno detache joinmodellato da vicino i thread POSIX.