Re: [asio-users] Can't catch Boost.Asio exceptions inside coroutines
Brought to you by:
chris_kohlhoff
From: Sergey S. <rk...@rk...> - 2016-10-27 11:49:30
|
Solved this with #define BOOST_ASIO_DISABLE_THREADS I've compiled gdb for Windows and started the test program with it. On Windows there were 3 threads and on Linux only 1 so I tried to recompile Boost with threadapi=pthread (just in case there's an issue with threading) but in the end it didn't compile libboost_thread*.a and I gave up. After a while I realized that the exception could be thrown in one thread and caught (unsuccessfully) in the main thread or some other so I googled for how to disable ASIO threads and that really helped. MXE uses threadapi=win32 and threading=multi, probably switching the latter to single and recompiling boost would help as well but it seems not to be an easy task with MXE. As I found out there's little to no info about that threading option (found only this answer: http://stackoverflow.com/questions/20859761/what-exactly-does-threading-multi-do-when-compiling-boost and it doesn't mention any issues with exceptions) so I don't know if it breaks something else if I change it and what exactly changes in multithreaded boost. For instance, how to deal with exceptions in my case. Maybe that's a flaw in ASIO itself but I'd refrain from drawing any conclusions. Honestly, I don't like it when an abstraction leaks this badly and instead of added "behind the scenes" efficiency I have to deal with uncaught exceptions that are clearly have to be caught in this simplest piece of code. 2016-10-27 9:01 GMT+03:00 Sergey Shpikin <rk...@rk...>: > Good to know that at least one configuration is working, thank you for > testing! That MinGW build is for Windows, unfortunately, and I'd like > to compile on Linux for Windows. > > 2016-10-27 8:40 GMT+03:00 niXman <i.n...@au...>: >> Sergey Shpikin 2016-10-26 18:48: >>> I have this little example of Boost.Asio code: >>> http://codepad.org/tuQedXI7 It works as expected on Linux producing >>> 1 >>> 2 >>> Caught Host not found (authoritative) >>> >>> but on Windows it crashes with: >>> 1 >>> 2 >>> terminate called after throwing an instance of >>> 'boost::system::system_error' >>> what(): Unknown error >>> >>> Tested on Windows Server 2008, Windows 7 and Wine, everything is the >>> same. I'm compiling on Linux for Windows with MXE ( http://mxe.cc/ ) >>> on GCC 4.9.4, Boost version is 1.60.0. I'm really stuck at this point >>> as nothing in Google looks a valid solution for the case and I already >>> have a working application on Linux but it crashes on any network >>> error on Windows. >>> >>> On Windows coroutines prevent any exceptions from being caught when >>> the program is compiled with -O1/2/3 but they're caught with -O0 or >>> -Os (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267 — this is >>> about GCC on FreeBSD but the same seemingly applies to MinGW). >>> However, boost's own exceptions, like the aforementioned >>> boost::system::system_error, still can't be caught. >> >> Works as expected for me using i686-6.2.0-release-posix-dwarf-rev1[1] & >> boost-1.62. >> >> >> >> [1] >> https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/6.2.0/threads-posix/dwarf/i686-6.2.0-release-posix-dwarf-rt_v5-rev1.7z >> >> -- >> Regards, niXman >> ___________________________________________________ >> Dual-target(32 & 64-bit) MinGW-W64 compilers for 32 and 64-bit Windows: >> http://sourceforge.net/projects/mingw-w64/ >> >> ------------------------------------------------------------------------------ >> The Command Line: Reinvented for Modern Developers >> Did the resurgence of CLI tooling catch you by surprise? >> Reconnect with the command line and become more productive. >> Learn the new .NET and ASP.NET CLI. Get your free copy! >> http://sdm.link/telerik >> _______________________________________________ >> asio-users mailing list >> asi...@li... >> https://lists.sourceforge.net/lists/listinfo/asio-users >> _______________________________________________ >> Using Asio? List your project at >> http://think-async.com/Asio/WhoIsUsingAsio |