boost scoped_lock mutex崩溃

时间:2010-05-21 12:26:30

标签: c++ multithreading boost

我在这些函数中保护了std :: queue的访问函数,push,pop,size,boost :: mutexes和boost :: mutex :: scoped_lock

不时在一个范围锁中崩溃

调用堆栈是这样的:

0  0x0040f005  boost::detail::win32::interlocked_bit_test_and_set  include/boost/thread/win32/thread_primitives.hpp  361
1  0x0040e879  boost::detail::basic_timed_mutex::timed_lock  include/boost/thread/win32/basic_timed_mutex.hpp  68
2  0x0040e9d3  boost::detail::basic_timed_mutex::lock  include/boost/thread/win32/basic_timed_mutex.hpp  64
3  0x0040b96b  boost::unique_lock<boost::mutex>::lock  include/boost/thread/locks.hpp  349
4  0x0040b998  unique_lock  include/boost/thread/locks.hpp  227
5  0x00403837  MyClass::inboxSize - this is my inboxSize function that uses this code:

MyClass::inboxSize ()
{
 boost::mutex::scoped_lock scoped_lock(m_inboxMutex);
 return m_inbox.size();
}

and the mutex is declared like this:
boost::mutex    m_inboxMutex;

它在此函数的最后一个粘贴行崩溃:

    inline bool interlocked_bit_test_and_set(long* x,long bit)
    {
        long const value=1<<bit;
        long old=*x;

和x具有此值:0xababac17

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

x的值看起来很可疑。

它看起来与0xabababab类似,它可能是在调试模式下分配给内存的初始值,或者可能是保护值的一部分,用于指示分配的内存块是否写入超出结束或开始

你能追溯一下这个价值的来源吗?

答案 1 :(得分:0)

我认为您没有正确创建MyClass的实例。就像指向MyClass的指针一样,它没有正确初始化,然后以这种方式使用ptr->inboxSize()