title: Multiple threads inside class accessing data
body: <p>I've read that different threads share the same memory segments apart from the stack. There is something i've been trying to understand. I have a class which creates different threads. Below is a simple example of what I am doing, creating one thread in the constructor.</p>
  
  <p>When an object of this class is created, in main() for example, all the threads can access the same member variables. If every thread gets its own stack, why doesn't each thread get a copy of the member variables rather than access to the same variable. I have looked around and I'm trying to get a picture in my mind of what is going on in memory here with the different stack frames. Many thanks in advance for any replies.  </p>
  
  <pre><code>////////////////////////    
  MyClass::MyClass()
  {
      t1 = std::thread([this] { this-&gt;threadFunc(); });
      t1.detach();
  
  }
  
  /////////////////////////
  
  void MyClass::threadFunc()
  {
      ///do stuff.. update member variables etc.
  }
  </code></pre>