JahSumbar
JahSumbar

Reputation: 71

boost scoped_lock mutex crashes

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  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;

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

Upvotes: 7

Views: 3538

Answers (2)

user184968
user184968

Reputation:

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().

Upvotes: 0

David Sykes
David Sykes

Reputation: 49882

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?

Upvotes: 2

Related Questions