Will non local constants be initialized before used by lambda executed from another thread?

  c++

if I in one translation unit defines constants used to access into a std::map, and passes a lambda which uses these constants to an object accessed in another thread, can I then be sure the constants are initialized?

In the code below: an object of class A i instantiated in the main thread. In A’s constructor it registers a callback with an object.
Say this object is accessed from another thread, defined in another translation unit, and calls the callback, will the value of kInsertString be correctly initialized at this time, or will I get a crash caused by trying to access the map using unitialized variables?

const std::string kInsertString{"MyValue"};

class A {
 public:
   A(Object& obj) {
     obj.registerCallback([this](int n){ update(n); });
   }

 private:
   void update(int v) {
     values[kInsertString] = v;
   }

   std::map<std::string, int> values;
};

Source: Windows Questions C++

LEAVE A COMMENT