我正在将一个 C++ 程序从 FreeBSD 移植到 RHEL。当我测试我的程序时,我发现调用 boost::shared_ptr::~shared_ptr() 时进程会挂起。
我使用 gdb 附加挂起进程,堆栈跟踪是:
(gdb) bt
#0 0x00e01430 in __kernel_vsyscall ()
#1 0x00bd8d96 in __pause_nocancel () from /lib/libpthread.so.0
#2 0x00bd30b2 in __pthread_mutex_lock_full () from /lib/libpthread.so.0
#3 0x04a60a26 in pthread_mutex_lock () from /lib/libc.so.6
#4 0x08069b61 in boost::detail::lightweight_mutex::scoped_lock::scoped_lock(boost::detail::lightweight_mutex&) ()
#5 0x080699d3 in boost::detail::sp_counted_base::release() ()
#6 0x08069999 in boost::detail::shared_count::~shared_count() ()
#7 0x08069952 in boost::shared_ptr<SS::Conf::SSConfNode>::~shared_ptr() ()
#8 0x00124fde in SS::Conf::SSConfManager::createConfFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /home/y/lib/libSS_conf.so.1
#9 0x00125e0c in SS::Conf::SSConfManager::createAllConfFiles() () from /home/y/lib/libSS_conf.so.1
#10 0x0012946b in SS::Conf::SSConfManager::initFromDisk(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /home/y/lib/libSS_conf.so.1
#11 0x00129c3b in SS::Conf::SSConfManager::configure(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /home/y/lib/libSS_conf.so.1
#12 0x00156d0c in SS::Init::configure() () from /home/y/lib/libSS_init.so.1
#13 0x0805ac63 in SS::Main::init() ()
#14 0x0807117e in main ()
而我的进程只包含一个线程:
(gdb) info thread
* 1 Thread 0xf77a8a40 (LWP 16724) 0x00c54430 in __kernel_vsyscall ()
当我在头文件中取消定义BOOST_HAS_THREADS并重建程序时,一切顺利。
boost 版本是 1.32,我在 RHEL4.8 上使用 gcc 3.4.6-11。