Boost logo

Boost Users :

From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2005-12-14 11:41:47


David M Garza wrote:

>smart_ptr_test still fails. I compiled with
>
>g++ -I ../../.. -D_REENTRANT -pthread -g -o smart_ptr_test
>smart_ptr_test.cpp
>
>The gdb output is
>
>(gdb) run
>Starting program:
>/disk3/users4/dgarza/boost_test/boost_cvs/boost/libs/smart_ptr/test/smart_ptr_test
>
>UDT with value 999888777 being destroyed
>UDT with value 111222333 being destroyed
>
>Program received signal SIGSEGV, Segmentation fault
> si_code: 1 - SEGV_MAPERR - Address not mapped to object.
>0x400f881 in boost::detail::atomic_increment (pw=0x40006cc4)
> at sp_counted_base_gcc_ia64.hpp:51
>warning: Compilation directory is not absolute; could result in
>incorrect behavior. Please report to HP.
>51 "r"(pw));
>(gdb) where
>#0 0x400f881 in boost::detail::atomic_increment (pw=0x40006cc4)
> at sp_counted_base_gcc_ia64.hpp:51
>#1 0x400f830 in boost::detail::sp_counted_base::add_ref_copy
>(this=0x40006cc0)
> at sp_counted_base_gcc_ia64.hpp:130
>#2 0x400f7b0 in boost::detail::shared_count::shared_count
>(this=0x7ffff2e4,
> r=@0x7ffff2d4) at shared_count.hpp:216
>#3 0x400fb60 in boost::shared_ptr<int>::boost::shared_ptr<int> (
> this=0x7ffff2e0, _ctor_arg=@0x7ffff2d0) at smart_ptr_test.cpp:165
>#4 0x400b210:0 in test () at smart_ptr_test.cpp:165
>#5 0x400ee90:0 in main () at smart_ptr_test.cpp:308
>
>I grabbed the CVS instead of using the 1.33.0 package I was working with
>before. I assume this was what you intended?
>
>
Did you also apply the patch I attached? I won't commit that change to
CVS unless and until you confirm that it works in an ILP32 configuration.

>As an aside, do I gather correctly from the presence of "-D_REENTRANT
>-pthread" the smart pointer code is multithreaded?
>
It's intended to be thread-safe if necessary. The purpose of the
assembly-language code is to do reference-counting in a thread-safe and
efficient way (use of mutexes for reference-counting is quite expensive).

>Anything I write using smart pointers, regardless of whether or not my code is multithreaded, will require the flags?
>
>
If BOOST_DISABLE_THREADS is defined then you will get a non-thread-safe
and more efficient version of sp_counted_base. You must ensure that all
translation units that use sp_counted_base get a consistent definition
(the One Definition Rule). So you should choose either "-D_REENTRANT
-pthread" or "-DBOOST_DISABLE_THREADS" and use it consistently.

Ben.


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