title: boost io_service initialization SIGSEGV
body: <p>I'm writing a smpp client and I have a problem that I can't solve. I wrote a <strong>tcp_client</strong> class with an internal <strong>io_service</strong> class to encapsulate all the process of the tcp comunication. After that I realize that I need that control in inherited classes, to run another tasks to be done, so, I modified the tcp_client to initialize the io_service in the constructor of the inherited class, and <strong>post</strong> from there.</p>
  
  <p>The <strong>tcp_client</strong> class:</p>
  
  <pre><code>class tcp_client
  {
  public:
      tcp_client(boost::asio::io_service &amp;_io_service, tcp::resolver::iterator endpoint_iterator)
        : m_io_service(_io_service), socket_(_io_service)
      {
          connect_start(endpoint_iterator);
          // this works OK
      }
  
      tcp_client(boost::asio::io_service &amp;_io_service)
      :m_io_service(_io_service),socket_(m_io_service)
      {
          // SIGSEGV
      }
  
      tcp_client(void)
      :m_io_service(tcp_io_service),socket_(m_io_service)
      {
          // Works OK
      }
  
      void connect(const char *host, const char *port)
      {
      if( get_tcp_status()==CONNECTED || get_tcp_status()==CONNECTING )
      {
          do_close();
      }
      tcp::resolver::query query(host,port);
      tcp::resolver resolver(m_io_service);
      tcp::resolver::iterator iterator = resolver.resolve(query);
      connect_start(iterator);
      m_io_service_thread = boost::thread(boost::bind(&amp;boost::asio::io_service::run,&amp;m_io_service));
      }
  private:
      boost::asio::io_service &amp;tcp_io_service;
      .........................
      .........................
  }
  </code></pre>
  
  <p>In the constructor</p>
  
  <pre><code>tcp_client(boost::asio::io_service &amp;_io_service)
          :m_io_service(_io_service),socket_(m_io_service)
          {
  
          }
  </code></pre>
  
  <p>I receive a SIGSEGV signal, about a mutex. The others contructors works very well, but this stop me. I'm able to continue the develop using the other constructors that works OK, but I want to know what is the problem here, just for sport (to learn).</p>
  
  <p>The inherited class that I use for this is:</p>
  
  <pre><code>class smpp_client : public tcp_client
  {
  private:
     boost::asio::io_service smpp_io_service;
  public:
      smpp_client(boost::asio::io_service &amp;_io_service, tcp::resolver::iterator endpoint_iterator)
        :tcp_client(_io_service,endpoint_iterator),
         m_smpp_status(SC_BIND_DISCONNECTED),
         rx_thread_exit(false)
        {
       m_windowing = 10;
       initialize_stack();
        }
  
     smpp_client(void):
        tcp_client(smpp_io_service),
        m_smpp_status(SC_BIND_DISCONNECTED),
        rx_thread_exit(false)
        {
       m_windowing = 10;
       initialize_stack();
       //smpp_io_service.post(boost::bind(&amp;smpp_client::rx_loop,this));
        }
  ...........
  ...........
  }
  </code></pre>
  
  <p>The first constructor in this class works OK, but the second call the constructor in tcp_client that rise a SIGSERV signal.</p>
  
  <p>The main is:</p>
  
  <pre><code>/*boost::asio::io_service io_service;
  tcp::resolver::query query(argv[1],argv[2]);
  tcp::resolver resolver(io_service);
  tcp::resolver::iterator iterator = resolver.resolve(query);
  
  smpp_client c(io_service,iterator);
  
  boost::thread t(boost::bind(&amp;boost::asio::io_service::run,&amp;io_service));*/
  
  smpp_client c; // --&gt; HERE SIGSEGV
  </code></pre>
  
  <p>I have tested with gdb and valgrind, the information in the output is the same:</p>
  
  <p>Program received signal SIGSEGV, Segmentation fault.
  0x00007ffff6bdbe64 in pthread_mutex_lock () from /lib64/libpthread.so.0</p>
  
  <p>I check all addresses and values at that point, and I have no idea how to fix it.</p>
  
  <p>I'm using Linux Slackware 13.37 with boost 1.49 and gcc 4.7.1</p>
  
  <p>PD: complete code can be watched at <a href="https://github.com/jpcordovae/smpp_client" rel="nofollow">https://github.com/jpcordovae/smpp_client</a> but not updated at this error.</p>