
Hi all, I have a class class Connection { ... ~Connection() { _socket.close(); } void receiveHandler() { // will crash } tcp::socket _socket; } io_service.run() is called in a working thread, and there are many other sockets runing on the io_service. I call async_read on the _socket, and bind Connection::receiveHandler() as the handler function. Then I delete the Connection object in main thread, the receive operation will be cancelled and the receiveHandler() will be called with errcode boost::asio::error::operation_aborted, but at that time, the Connection object has been deleted, calling receiveHandler() will crash if it access the object's data member. Because there are still other sockets running on the io_service, I can't just join the working thread in Connection's destructor. I want to ensure the socket is closed completely and no more handler will be called in the destructor. One method is create an event before calling _socket.close(), then wait for the event, in receiveHandler(), set the event. Are there any easier method to do this? Thanks, Wang Yun