title: Synchronization done by class destructors
body: <p>I've got question about multithreading. I have a pretty big project and now I am writing some exe client to use all of that code. It involves multithreading and inter-process communication. I've got main which looks like this:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
  std::unique_ptr&lt;CommunicationWrapper&gt; wrapper;
  
  wrapper = std::make_unique&lt;CommunicationWrapper&gt;(argv[1]);
  wrapper-&gt;run();
  
  return 0;
  }
  </code></pre>
  
  <p>Underneath there is a class which is doing inter-process communication which looks like this:</p>
  
  <pre><code>CommunicationEngine::CommunicationEngine()
   : m_processingLoop(std::async(std::launch::async, [this]() { processingLoop(); }))
  {}
  
  CommunicationEngine::~CommunicationEngine()
  {
     m_processingLoop.wait();
  }
  
  //some long function that do a lot of stuff based on messages from anothre process
  void CommunicationEngine::processingLoop() const 
  </code></pre>
  
  <p>This code work without a problem but I want to know if it is considered good practice and good design to do the synchronization (waiting) on call of destructor? What are possible pitfals of that approach?</p>