title: Threaded implementation of observer pattern - C++
body: <p>I'm developing a C++ program which has a "scan" method which will trigger a relatively long running scanning procedure. When the procedure is completed, the scan method will notify observers of results using the observer pattern. </p>
  
  <p>I would like to create a separate thread for each scan. This way I can run multiple scans simultaneously. When each scanning process completes, I would like the scan method to notify the listeners.</p>
  
  <p>According the boost thread library, it looks like I can maybe do something like this:</p>
  
  <pre><code>#include &lt;boost/thread/thread.hpp&gt;
  #include &lt;boost/thread/mutex.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;iostream&gt;
  
  boost::mutex io_mutex;
  
  void scan(int scan_target, vector&lt;Listener&gt; listeners)  
  {
    //...run scan 
    {
      boost::mutex::scoped_lock  
        lock(io_mutex);
      std::cout &lt;&lt; "finished scan" &lt;&lt; endl;
      // notify listeners by iterating through the vector
      // and calling "notify()
  
    }
  }
  
  int main(int argc, char* argv[])
  {
  
    vector&lt;Listener&gt; listeners
    // create 
    boost::thread thrd1(
      boost::bind(&amp;scan, 1, listeners));
    boost::thread thrd2(
      boost::bind(&amp;scan, 2, listeners));
    //thrd1.join();
    //thrd2.join();
    return 0;
  } 
  </code></pre>
  
  <p>Does this look roughly correct? Do I need to mutex the call to listenrs? Is it ok to get rid of the joins? </p>