title: Can C++ std::thread callable's object pointer be invalidated after the thread begins execution?
body: <p>I have this chunk of code...</p>
  <p>A non-static member method (serving as callable for thread):</p>
  <pre><code>void Object::unregister()
  {
     ...
  }
  </code></pre>
  <p>and destructor like this:</p>
  <pre><code>Object::~Object()
  {
    std::thread cleanup(&amp;Object::unregister, this);
    cleanup.detach();
  }
  </code></pre>
  <p>What I see as a problem is that I am running a thread with parameter <code>this</code> which become invalidated when destructor finishes, so I assume it is dangerous, because I do not have any garantee, that the cleanup thread already started - and this my subquestion - <strong>is safe if <code>this</code> would be invalidated (destructor finishes) before the call to <code>unregister</code> finishes completely</strong> <em>(in other words is it ok, if it already started, but did not finish completely)</em><strong>?</strong></p>
  <p>I would say that answer is <em><strong>No</strong></em> as the copy of <code>this</code> pointer is used with callable, but I am not sure as the app behaves, like it does not mind and everything is OK.</p>
  <p>If it is ok that thread just started and did not finish yet, is there any way to know that the thread is already running? Would usage of call to <code>joinable()</code> return me <code>true</code> just when the thread is already executing or it can return <code>true</code> before the thread's execution started?</p>
  <p><strong>Is there any way how to do it safe and be sure that callable</strong> <code>&amp;Object::unregister</code> <strong>and</strong> <code>this</code> <strong>will not be invalidated, because</strong> <code>Object</code> <strong>was destroyed meanwhile?</strong></p>