I have a boost::thread that does synchronous reads on boost::asio::serial_port . When I destroy an instance of a class that contains both, I want the thread to end gracefully, even if it is blocked while reading. How can i do this?
Looking at the docs , I tried cancel , but it only works for asynchronous read / write. Then I tried close , but I have an exception, and it was not the kind from which you can recover. Perhaps using send_break or native_handle ? (this is Windows and portability is not critical)
Update : I also tried stop io_service pass to the serial port object constructor, but read not unlocked.
Change The exception is actually "exciting", but I would not want to put a try / catch block inside the destructor, and refactoring the code to perform the shutdown process outside the destructor would cause many changes in the upper layers. Therefore, I would only go for this decision if some Boost authority says that there is no other way.
dario_ramos
source share