[Boost-user]multithreaded app hangs in boost libraries

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: 18 _dl_sysinfo_int80() 0x003317a2 17 __lll_mutex_lock_wait() 0x0062e30e 16 _L_mutex_lock_35() 0x0062af3b 15 <symbol is not available> 0x080c80e8 14 <symbol is not available> 0x00472ff4 13 <symbol is not available> 0x080c80e8 12 <symbol is not available> 0xbffff6b0 11 <symbol is not available> 0xbffff208 10 pthread_mutex_lock() 0x0042097e 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 5 shared_ptr() /usr/include/c++/3.4.6/bits/stl_construct.h:81 0x0807a7c8 4 boost::program_options::options_description_easy_init::operator() libs/program_options/src/options_description.cpp:178 0xb7fd7189 3 Settings() ../Settings.cpp:9 0x08081808 If this post sounds familiar, that's because this is my second attempt to get this problem resolved. Previously I have been told that this sounds like I've built my application with single-threading, and linked it to multi-threaded build of a boost library, or vice versa. Could you please let me know what's the right way to build my app with multi-threading. I am using Boost 1.34 libraries on Linux and compile with gcc 3.4.6 Thank you in advance for your help, Inga

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); 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?

On a closer inspection of the stacktrace it looks like some of the header files are picked up from the /usr/include directory, instead of my local install of boost. When I compile, I explicitly provide the right include path to the compiler. I have my local installation of boost in LD_LIBRARY_PATH. Should I be doing something at runtime for includes as well? Thanx in advance for all the help, Inga -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Thursday, July 05, 2007 9:53 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [Boost-user]multithreaded app hangs in boostlibraries 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); 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Farberov, Inga wrote:
On a closer inspection of the stacktrace it looks like some of the header files are picked up from the /usr/include directory, instead of my local install of boost. When I compile, I explicitly provide the right include path to the compiler. I have my local installation of boost in LD_LIBRARY_PATH.
It could be that includes of the form "boost/header.hpp" are picking up your
local installation, while includes of the form
participants (2)
-
Farberov, Inga
-
Peter Dimov