
I'm writting a multiplatform app which uses a tcp::acceptor. Thread one does: { std::cout<<"Oh but I interupted: "<<std::endl; _myTCPAcceptor->close(); std::cout<<"Done interupting "<<std::endl; } std::cout<<"About to join "<<std::endl; _myAcceptorThread->join(); std::cout<<"Join complete"<<std::endl; Thread two does:
{ boost::system::error_code ec; boost::asio::socket_base::non_blocking_io command(false); _mySocket.io_control(command,ec);
boost::system::error_code ec1; std::cout<<"About to accept "<<std::endl; _myTCPAcceptor->accept(_mySocket,ec1); std::cout<<boost::system::system_error(ec1).what()<<std::endl; std::cout<<"done with the accept"<<std::endl; }
According to the reference: http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/reference/ip__tcp/a... acceptor object is not threadsafe. This means you should not access it this way, and if you do, the behaviour is undefined. To cancel acceptor you could use async_accept() and then post close() to the same thread, using io_service.post().