title: Memory sharing between C++ threads
body: <p>I'm new to threading in C++, and I'm trying to get a clear picture about how memory is shared/not shared between threads. I'm using <code>std::thread</code> with C++11.
  From what I've read on other SO questions, <strong>stack</strong> memory is owned by only one thread and <strong>heap</strong> memory is shared between threads. So from what I think I understand about the stack vs. the heap, the following should be true:</p>
  
  <pre><code>#include &lt;thread&gt;
  using namespace std;
  
  class Obj {
  public:
      int x;
      Obj(){x = 0;}
  };
  
  int main() {
      Obj stackObj;
      Obj *heapObj = new Obj();
      thread t([&amp;]{
          stackObj.x++;
          heapObj-&gt;x++;
      });
      t.join();
      assert(heapObj-&gt;x == 1);
      assert(stackObj.x == 0);
  }
  </code></pre>
  
  <p>forgive me if I screwed up a bunch of stuff, lambda syntax is very new to me. But hopefully what I'm trying to do is coherent.
  Would this perform as I expect? And if not, what am I misunderstanding?</p>