Notify_all导致分段错误

notify_all causes segmentation fault

本文关键字:分段 错误 all Notify      更新时间:2023-10-16

我正在使用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 ()

在没有实际看到代码的情况下,这主要是猜测。

从你的调试:

#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)。是否有可能在尝试使用条件变量之前删除它?