开发者

boost scoped_lock mutex crashes

开发者 https://www.devze.com 2023-01-01 02:17 出处:网络
I have protected a std::queue\'s access functions, push, pop, size, with boost::mutexes and boost::mutex::scoped_lock in these functions

I have protected a std::queue's access functions, push, pop, size, with boost::mutexes and boost::mutex::scoped_lock in these functions

from time to time it crashes in a scoped lock

the call stack is this:

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  incl开发者_开发技巧ude/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;

it crashes at the last pasted line in this function:

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

and x has this value: 0xababac17

Thanks for the help


The value of x looks suspicious to me.

It looks vaguely similar to 0xabababab which could be an initial value given to allocated memory in debug mode, or possibly part of guard values to indicate if allocated memory blocks are written beyond the end or beginning

Can you trace back where that value came from?


I think you did not create an instance of MyClass correctly. Like a pointer to MyClass that was not initialized correctly and then used in this way ptr->inboxSize().

0

精彩评论

暂无评论...
验证码 换一张
取 消