notify_all导致分段错误

时间:2013-04-23 13:46:00

标签: c++ multithreading boost boost-thread

我正在使用boost线程,在析构函数中调用notify_all()后,我看到了一个分段错误。这是堆栈:

(gdb) where
#0  0x00007ffff752de84 in pthread_mutex_lock ()
   from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007fffe85ab22e in        boost::pthread::pthread_mutex_scoped_lock::pthread_mutex_scoped_lock (this=0x7fffffffdba0, m_=0x0)
    at /usr/include/boost/thread/pthread/pthread_mutex_scoped_lock.hpp:26
#2  0x00007fffe85abb5d in boost::condition_variable::notify_one (this=0x0)
    at /usr/include/boost/thread/pthread/condition_variable.hpp:88
#3  0x00007fffe8690864 in CampaignFrequency::stopFlushThread (this=0x6ad590)
    at /home/git/gitRTB/infinityplus/src/common/shm/CampaignFrequency.cpp:197
#4  0x00007fffe868ffd7 in CampaignFrequency::~CampaignFrequency (
    this=0x6ad590, __in_chrg=<optimised out>)
    at /home/git/gitRTB/infinityplus/src/common/shm/CampaignFrequency.cpp:81
#5  0x00007fffe85bdc37 in rtb_child_init (s=0x7ffff7fc3238)
    at /home/git/gitRTB/infinityplus/src/bidder/mod_rtb.cpp:265
#6  0x000000000044784c in ap_run_child_init ()
#7  0x000000000042817c in ?? ()
#8  0x0000000000463594 in ?? ()
#9  0x00000000004635f4 in ?? ()
#10 0x00000000004643fd in ?? ()
#11 0x000000000042f026 in ap_run_mpm ()
#12 0x0000000000428d74 in main ()

1 个答案:

答案 0 :(得分:2)

如果没有真正看到代码,这主要是猜想。

从您的调试:

#2  0x00007fffe85abb5d in boost::condition_variable::notify_one (this=0x0)
    at /usr/include/boost/thread/pthread/condition_variable.hpp:88

它说这(在条件变量内)是nullptr。您似乎在调用cv->notify_all(),其中cv是nullptr(又名0)。您是否有可能在尝试使用之前删除条件变量?