mercredi 29 août 2018

boost::asio hangs _endthreadx

int main(){
  boost::asio::io_context io_context;
  Server server(io_context, SOCKET_ADDRESS, SOCKET_PORT);

  std::thread thread_server([&]() {
    server.start();
    io_context.run();
  });

  std::thread thread_client([&]() {
    Client &client = Client::create(SOCKET_ADDRESS, SOCKET_PORT);
    client.start();
    done = true; // <-----atomic
  });

  std::thread thread_stop([&]() {
    while (done == false) {
      std::this_thread::sleep_for(std::chrono::milliseconds(5));
    }
    server.stop();
  });

  thread_server.join();
  thread_client.join();
  thread_stop.join();
}

I am experimenting with boost::asio and encountered problem which I am unable to solve. When I run program(simpler example above) on Linux(compiled with gcc) everything is fine. Same when I run it on Release in VS2017CE. However when I run it on Debug(VS2017CE as well) it crash with and exception:

cannot dereference string iterator because string iterator was invalidated

It crash on _endthreadx either when exiting thread_stop or thread_server(most likely second one). Here are my questions then:

  1. What are the differences between Release and Debug basic configurations which might affect code execution and point me where should I look.(I am aware of some but couldn't find anything connected with this particular problem.)

  2. What mistakes were made by me which affects code execution.

I've made some classes so I will provide more code if neccessary, but code basically works so I am starting with just a piece of it.

Aucun commentaire:

Enregistrer un commentaire