After some reading it seems to me that there is no portable way to guarantee that a detached std::thread
will not cause memory leaks or even undefined behavior once the main thread finishes execution. It obviously can't be joined once it has been detached, there doesn't seem to be a mechanism to detect whether detached threads exit from the main thread and the STL does not provide an analogue of pthread_exit
.
It seems to me that this implies that once I detach a thread I basically have to pray that is has finished executing before the main thread returns from main
or bad things might happen. Is this correct? Or am I missing something?
Aucun commentaire:
Enregistrer un commentaire