title: C++ static variable and multiple processes
body: <p>I have a C++ program which forks child processes to do some work. In these child processes some classes are created and there is a static variable inside a member function like so:</p>
  
  <pre><code>void MyClass::foo () {
      static std::string uuid;
      ...
      uuid = "A new value";
  }
  </code></pre>
  
  <p>Since each process is freshly forked, I assumed uuid to always be initialized as an empty string. However, in some cases I noticed the uuid already has been given a value upon the first entry of the function, which causes problems. </p>
  
  <p>How can this static variable be initialized across forked processes? And is my only option to use an class variable?  The reason for the static variable is that I didn't want to introduce class variables which are only used inside a single function so to keep the class nice and tidy.</p>