Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-07-05 09:52:35


Farberov, Inga wrote:
> Hello,
>
> I have written a static library that uses boost program_options,
> threads, date-time and serialization libraries. There is also an
> extensive use of shared_ptr.
>
> I am working on a multithreaded application, so when I link my library
> into the executable, I use multithreaded versions of the boost
> libraries. When I compile my library and application that links to
> it, I use -pthread flag in attempt to make it multi-threaded.
>
> Everything compiles and links without a problem, however when I try to
> run the application, it hangs. I have tried to bedug it and when I
> suspend a hanging thread it gives me following stack trace:

...

> 9 pthread_mutex_lock() 0x0042097e
>
> 8 scoped_lock() /usr/include/boost/detail/lwm_pthreads.hpp:72
> 0x080598eb
>
> 7 boost::detail::sp_counted_base::add_ref_copy()
> /usr/include/boost/detail/shared_count.hpp:122 0x0805b679
>
> 6 shared_count()
> /usr/lib/boost/include/boost-1_34/boost/detail/shared_count.hpp:216
> 0x0805b65b

This stack trace makes no sense to me. I understand the shared_count:216
portion; it's the line:

        if( pi_ != 0 ) pi_->add_ref_copy();

But the next level, add_ref_copy is shown to be at shared_count.hpp:122, and
there's no add_ref_copy there. shared_count:122 is the line

        pi_ = new sp_counted_impl_pd<P, D>(p, d);

in the no-exception branch of shared_count( p, d ).

Next down the stack we have scoped_lock at lwm_pthreads.hpp:72; this is even
more baffling. add_ref_copy doesn't call into lwm_pthreads; it would
typically call into sp_counted_base_gcc_*.hpp if you CPU is x86, PPC or
IA64, or sp_counted_base_pt if it isn't.

Are you sure that you aren't using 1.34 headers and older libraries?

Have you used -DBOOST_SP_USE_QUICK_ALLOCATOR by any chance? Can you try
placing a

    static boost::shared_ptr<int> p( new int );

variable before your Settings variable? Can you try a debug version of
boost::program_options with inlining off, in a hope that this will produce a
more reliable stack trace?


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