title: boost::system::error_code::message() throwing access violation exception with boost::asio socket
body: <p>I am implementing a client application that has to make a small number of socket connections to hardware devices. I have broken down the problem to the following small code subset</p>
  
  <pre><code>boost::system::error_code ec;
  std::string str_message = ec.message();  // no access violation before connect()
  std::string str_port = "502";
  std::string str_ip = "192.168.12.198";
  
  boost::asio::io_service io_service;
  boost::asio::ip::tcp::resolver resolver(io_service);
  boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(),str_ip,str_port);
  boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
  boost::asio::ip::tcp::socket s(io_service);
  
  ec = s.connect(*iterator,ec);
  if (ec)
  {
      // connection error of some kind.
      std::string str_debug = ec.message();  // BANG!!!!
  
  }
  </code></pre>
  
  <p>I am using Embarcadero RAD studio XE4 C++ Builder and when I run the above code in the main VCL thread it works fine. When I run it with multiple connections, I have the above code running in multiple instances of the <code>TThread</code> class and that is when I get into problems with an access violation - it appears that when the <code>error_code</code> is modified by the <code>connect</code> call, the internal member <code>m_cat</code> of the <code>error_code</code> instance becomes NULL and so when I call <code>message()</code> I get the access violation. This happens even when I just have a single background thread running.</p>
  
  <p>Is it possible that my code above is simply not thread safe in the way I need to use it? I have tried to find out why this code won't run in a background thread, but cannot find anything about it. </p>
  
  <p>The boost version I am running is 1.50 as this is the integrated version that is used for building 64 bit applications in RAD studio.</p>
  
  <p>Has anyone else encountered this issue in a multithreaded setting (in Embarcadero or otherwise) and if so how did you resolve it? Or is this class simply not safe to use in a multithreaded way?</p>