title: C++ Session management methods
body: <p>I want to create a session management scheme that , in few words , has to be this way: </p>
  
  <ul>
  <li>A std::map to keep track of  the current active sessions (filled up 
  with id string and and an associated message queue)</li>
  <li>A set of threads on each message queue. </li>
  </ul>
  
  <p>There are two ways to create this scheme:</p>
  
  <ol>
  <li><p>Keep all the components in the main program and when needed fill up the map with a new session id and associated message queue and start a new detached thread with a reference to the queue that he will be polling on as argument. </p>
  
  <pre><code> //main program code
     _session_map[id] = queue;
     thread = new thread(&amp;queue);
     thread.detach();
     thread.start();
   //main program code
  </code></pre></li>
  <li><p>Create a session_manager class that hides all those mechanisms
  to the main program.</p>
  
  <pre><code> class session_manager
   {
      //session_manager code
      std::string new_session(std::string id)
      {
         _session_map[id] = queue;
         thread = new thread(&amp;queue);
         thread.detach();
         thread.start();
      }
  
      private:
        std::map&lt;std::string,message_queue&gt; _session_map;
   };
  </code></pre></li>
  </ol>
  
  <p>what is the better way to create this scheme? I'm not sure if the second scheme could work correctly because I'm not so expert on using threads. 
  Also I don't have a good idea on how to keep track of the closed sessions does anyone hve some suggestion?</p>