I have a singleton like this:
class MySingleton{
public:
void StartThread();
static MySingleton& GetInstance(){
static MySingleton st;
return st;
}
// copied forbidden here
...
//
private:
// resources defined here
...
//
};
void DoStuff(MySingleton*);
The function StartThread()
starts a detached std::thread to execute DoStuff(MySingleton*)
, which utilizes resources owned by the singleton instance.
My question is: Is it guaranteed that the thread exits before the singleton destructs(when the program exit) so that no released resources are utilzed?