Is it safe for detached thread to utilized resources owned by singleton

Viewed 44

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?

1 Answers
Related