|
Boost Users : |
Subject: Re: [Boost-users] Asio example 5 sagmentation fault
From: Anthony Foiani (tkil_at_[hidden])
Date: 2011-08-31 15:10:21
Alessandro, greetings --
Alessandro Candini <candini_at_[hidden]> writes:
> I'm really interested in exemple 5 of boost asio:
>
> http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/tutorial/tuttimer5/src.html
>
> I've tried it with boost-1.47.0. I can compile without warnings using:
>
> g++ -Wall -pedantic -lboost_thread -lboost_system -o timer5 timer5.cpp
>
> but when I launch the executable it gives me a Segmentation fault.
>
> Commenting the code I found that the segmentation fault raise at the
> 3rd line of main:
>
> boost::thread t(boost::bind(&boost::asio::io_service::run, &io));
>
> I'm trying on the following machine:
> Linux office-007 2.6.38-11-generic #48-Ubuntu SMP Fri Jul 29 19:02:55
> UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Not exactly the same setup, but on a very current gcc+boost on a
similar system, it seems to work fine:
$ uname -a
Linux foo 2.6.35.14-95.fc14.x86_64 #1 SMP \
Tue Aug 16 21:01:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.6.1/configure --prefix=/usr/local/gcc-4.6.1 \
--with-local-prefix=/usr/local/gcc-4.6.1/local \
--enable-languages=c,c++ --enable-threads
Thread model: posix
gcc version 4.6.1 (GCC)
$ g++ -Wall -pedantic -I/usr/local/boost/include \
-o boost-asio-segv boost-asio-segv.cpp \
-L /usr/local/boost/lib -lboost_thread -lboost_system
$ export LD_LIBRARY_PATH=/usr/local/gcc/lib64:/usr/local/boost/lib
$ ./boost-asio-segv
Timer 1: 0
Timer 2: 1
Timer 1: 2
Timer 2: 3
Timer 1: 4
Timer 2: 5
Timer 1: 6
Timer 2: 7
Timer 1: 8
Timer 2: 9
Final count is 10
$ ldd ./boost-asio-segv
linux-vdso.so.1 => (0x00007fffefda7000)
libboost_thread.so.1.47.0 => /usr/local/boost/lib/libboost_thread.so.1.47.0 (0x00007f7898f96000)
libboost_system.so.1.47.0 => /usr/local/boost/lib/libboost_system.so.1.47.0 (0x00007f7898d92000)
libstdc++.so.6 => /usr/local/gcc/lib64/libstdc++.so.6 (0x00007f7898a8e000)
libm.so.6 => /lib64/libm.so.6 (0x0000003da1a00000)
libgcc_s.so.1 => /usr/local/gcc/lib64/libgcc_s.so.1 (0x00007f789885a000)
libc.so.6 => /lib64/libc.so.6 (0x0000003da1200000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003da1600000)
librt.so.1 => /lib64/librt.so.1 (0x0000003da2200000)
/lib64/ld-linux-x86-64.so.2 (0x0000003da0e00000)
You might want to try using 'ldd' to make sure that it's pulling in a
consistent set of libraries (no 32/64 mismatch, no boost version
mismatch, etc).
Finally, use 'gdb' to see what is in "io" just before the segv. Just
looking at that line, I don't see how either of those addresses could
be null, which would be the usual cause of a segv. Maybe something
like:
void * run_addr = static_cast< void * >( &boost::asio::io_service_run );
void * io_addr = static_cast< void * >( &io );
And see if either of those are null?
If you have the resources, can you try building your own g++ and
boost, to see if it works under that combination?
If you still can't solve it, can you make sure to post the version of
g++ that you're using?
> "WARNING:This message contains confidential and/or proprietary
> information which may be subject to privilege or immunity and which
> is intended for use of its addressee only. Should you receive this
> message in error, you are kindly requested to inform the sender and
> to definitively remove it from any paper or electronic format."
And this sort of thing is pretty useless / rude on a public mailing
list, don't you think?
Best regards,
Tony
p.s. I could also get the exact same source code to run under the
"stock" install on up-to-date Fedora 14, which means g++ 4.5.1
and boost 1.44.0:
$ unset LD_LIBRARY_PATH
$ g++ -Wall -pedantic -o boost-asio-segv boost-asio-segv.cpp \
-lboost_thread-mt -lboost_system-mt
$ ./boost-asio-segv
Timer 1: 0
Timer 2: 1
Timer 1: 2
Timer 2: 3
Timer 1: 4
Timer 2: 5
Timer 1: 6
Timer 2: 7
Timer 1: 8
Timer 2: 9
Final count is 10
$ rpm -q gcc boost-thread
gcc-4.5.1-4.fc14.x86_64
boost-thread-1.44.0-8.fc14.x86_64
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net