title: C++ static variable inialization and threads
body: <p>I have the following bit of C++11 code that uses threads and static variable initialisations. My question is:</p>
  
  <p>What guarantees or assurances does the C++ language make about the single initialisation of static variables - the code below displays the correct values, however I can't seem to find the passage in the new standard that mentions how the memory model should interact with threads. When if ever do the variables become thread-local?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  
  class theclass
  {
  public:
     theclass(const int&amp; n)
     :n_(n)
     { printf("aclass(const int&amp; n){}\n"); }
     int n() const { return n_; } 
  private:
     int n_;
  };
  
  int operator+(const theclass&amp; c, int n)
  {
     return c.n() + n;
  }
  
  void foo()
  {
     static theclass x = 1;
     static theclass y = x + 1;
     printf("%d %d\n",x.n(),y.n());
  }
  
  int main()
  {
     std::thread t1(&amp;foo);
     std::thread t2(&amp;foo);
     t1.join();
     t2.join();
     return 0; 
  }
  </code></pre>