title: Is it ok/safe to delete a class that contains running threads when I want the threads to terminate?
body: <p>Here is a quick example:</p>
  
  <pre><code>class worker
  {
      std::thread thread1;
      std::thread thread2;
  
      worker(){}
  
      start()
      {
          thread1 = std::thread([]()
          {
              std::this_thread::sleep_for(std::chrono::milliseconds(50000));
          });
          thread1.deteach();
  
          thread2 = std::thread([]()
          {
              std::this_thread::sleep_for(std::chrono::milliseconds(50000));
          });
          thread2.deteach();
      }
  
      ~worker()
      {
          // Ignore this part! - as per Richard's comment :)
          //thread1.join();   // &lt;-- do I need this at all?
          //thread2.join();   // &lt;-- do I need this at all?
      }
  }
  
  int main()
  {
      worker *p_worker = new worker();
      p_worker-&gt;start();
      std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // 1 sec
  
      delete p_worker;
  }
  </code></pre>
  
  <ul>
  <li>Create the worker</li>
  <li>Start the threads which last for 50 seconds</li>
  <li>After 1 second delete the worker (calls destructor)</li>
  <li>In worker destructor I re-join the threads (probably should check if they are joinable first?) - not really sure I need to do this.</li>
  <li>Then worker is destroyed</li>
  </ul>
  
  <p>I had a look at this question: <a href="https://stackoverflow.com/questions/12207684/how-do-i-terminate-a-thread-in-c11">how-do-i-terminate-a-thread-in-c11</a> which suggests there is no c11 portable way to terminate the threads.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>Are the threads destroyed completely (no dregs/leaks left)?
  
  <ul>
  <li>If "yes" do I need to re-join the threads in order for them to be destroyed? <code>EDIT - Richard pointed out this is N/A</code></li>
  </ul></li>
  <li>Is this a sensible approach?</li>
  </ul>