title: Can multi threads access same weak_ptr object C++
body: <p>So I have this class:</p>
  
  <pre><code>class Test
  {
      ...
      std::weak_ptr&lt;W&gt; m_w;
      std::thread t1;
      std::thread t2;
  public:
      Test (const std::shared_ptr&lt;W&gt; w);
      void t1Task();
      void t2Task();
      ...
  }
  </code></pre>
  
  <p>In its constructor, pretty regular, they are initialized:</p>
  
  <pre><code>...
  m_w(w),
  ...
  t1 = std::thread (&amp;Test::t1Task, this);
  t2 = std::thread (&amp;Test::t2Task, this);
  </code></pre>
  
  <p>So here comes my question, can I use <code>lock()</code> in these 2 task functions considering they start at the same time like I do in the code below? If I can't, what can I do since I have to get a <code>shared_ptr</code> to <code>w</code> object in both threads?</p>
  
  <pre><code>    void Test::t1Task ( )
      {
          std::shared_ptr&lt;W&gt; wPtr = m_w.lock();   // 1st line of this func
          while(/*some condition*/)
          {
               // going to use wPtr in this while loop
          }
      }
  
      void Test::t2Task()
      {
          std::shared_ptr&lt;W&gt; wPtr = m_w.lock();   // 1st line of this func
          while(/*some condition*/)
          {
               // going to use wPtr in this while loop
          }
      }
  </code></pre>