title: Starting a std::thread with static linking causes segmentation fault
body: <p>To learn c++11 (and boost) I am writing a simple http-server using boost asio and c++11 (for threading and lambdas).</p>
  
  <p>I want to test the new c++11 lambdas and std::thread so I tried to start the <code>io_service.run()</code> like this in a std::thread with a lambda:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  using std::cout;
  using std::endl;
  using boost::asio::ip::tcp;
  
  class HttpServer
  {
  public:
      HttpServer(std::size_t thread_pool_size)
      : io_service_(),
      endpoint_(boost::asio::ip::tcp::v4(), 8000),
      acceptor_(io_service_, endpoint_)
      { }
  
      void Start() {
          acceptor_.listen();
          cout &lt;&lt; "Adr before " &lt;&lt; &amp;io_service_ &lt;&lt; endl;
          std::thread io_thread([this](){
              cout &lt;&lt; "Adr inside " &lt;&lt; &amp;io_service_ &lt;&lt; endl;
              io_service_.run();
          });
          io_thread.join();
      }
  
  private:
      boost::asio::io_service io_service_;
      tcp::endpoint endpoint_;
      tcp::acceptor acceptor_;
  };
  
  int main() {
      HttpServer server(2);
      server.Start();
  }
  </code></pre>
  
  <p>This terminates with segmentation fault. Additionally sometimes it is running the cout inside the lambda, sometimes not (although endl should flush). In any case, it prints the correct address of <code>io_service_</code>. However, when I replace the <code>std::thread</code> with a <code>boost::thread</code> (no other change!), everything is working fine.</p>
  
  <p>I would appreciate it if anyone has an idea where the problem is caused (could be asio, std::thread or std::lambda).</p>
  
  <p>Additional information:</p>
  
  <p>According to another <a href="https://stackoverflow.com/questions/7895879/using-member-variable-in-lambda-capture-list-inside-a-member-function">post</a> accessing the member io_service_ within a lambda is fine when capturing <code>this</code>, as I do it.</p>
  
  <p>I am running gcc 4.6.1 on Ubuntu and boost 1.46. G++ parameters:</p>
  
  <pre><code>g++ -std=c++0x -static -I/home/andre/DEV/boost_1_48_0/include/ -L/home/andre/DEV/boost_1_48_0/lib/ -o webserver main.cpp -lboost_system -lboost_thread -lpthread
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Removing -static fixed the problem. I found out that the problem has nothing to do with boost or lambdas and can be reproduced whenever building static and using <code>std::thread</code>. For any reason this combination does not work.
  I think this <a href="https://stackoverflow.com/questions/7090623/c0x-thread-static-linking-problem">post</a> describes almost the same, however I don't really understand the details and the error message is different.</p>
  
  <p>So I wonder why <code>std::thread</code> and static linking don't seem to work together. Is there a reason why static linking is not allowed here? I updated the question title and removed the boost tag.</p>