title: Am I paranoid while using boost:asio?
body: <p>I am write an app using boost:asio.</p>
  <p>I have a single io_serice::run() thread, and many worker threads. All the worker threads may send msg at any time.</p>
  <p>Here is how I implement the <code>send_msg()</code>.</p>
  <pre><code>// Note: send_msg() could be called from any thread.
  // 'msg' must be 'malloc'ed, and its owner ship will be transfered  to '_send_q'
  //
  //  NetLibConnection has base classes of tcp::socket and  boost::enable_shared_from_this
  void NetLibConnection::send_msg(PlainNetLibMsg*  msg)
  {
      AutoLocker __dummy(this-&gt;_lock_4_send_q);    // _lock_4_send_q is a 'mutex'
  
      bool write_in_progress = ! this-&gt;_send_q.empty(); // _send_q is std::deque&lt;PlainNetLibMsg* &gt;, 
                                             // the 'send_q' mechansim is learned from  boost_asio_example/cpp03/chat  
      this-&gt;_send_q.push_back(msg);
      if (write_in_progress)
      {
          return;
      }
  
      this-&gt;get_io_service().post(      // queue the 'send operation' to a singlton io_serivce::run() thread
  
          boost::bind(&amp;NetLibConnection::async_send_front_of_q
                  , boost::dynamic_pointer_cast&lt;NetLibConnection&gt;(shared_from_this())
          ) 
      );
        
  }
  
  void NetLibConnection::async_send_front_of_q()
  {
      boost::asio::async_write(*this 
          , boost::asio::buffer( this-&gt;_send_q.front() , _send_q.front()-&gt;header.DataSize + sizeof(NetLibChunkHeader) )
          , this-&gt;_strand.wrap(  // this great post   https://stackoverflow.com/questions/12794107/why-do-i-need-strand-per-connection-when-using-boostasio/
                                // convinced me that I should use strand along with  Connection
              boost::bind( &amp;NetLibConnection::handle_send
                          , boost::dynamic_pointer_cast&lt;NetLibConnection&gt;(shared_from_this()) 
                          , boost::asio::placeholders::error
              )
          )
      );
  }
  </code></pre>
  <p>The code works fine. But I am not satisfied with its verbosity. I feel the <code>senq_q</code> acts as the same role of <code>strand</code>.
  Since</p>
  <ol>
  <li>all real <code>async_write</code> call happen in a single <code>io_service::run()</code> thread</li>
  <li>all real <code>async_write</code> are queued one-by-one via the <code>send_q</code></li>
  </ol>
  <p>Do I still need the <code>strand</code>?</p>