views:

144

answers:

2

hello,

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

+1  A: 
David Sykes
i kind of got lost in the boost source
JahSumbar
Mark B
A: 

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

skwllsp
the instance is ok, in call's many of the class' functions until this, and I don't delete the class
JahSumbar
class functions that use member data?
Nikko
yes, class functions that use member data, even this function
JahSumbar
Do you suspect the Boost.Thread? Honestly, I am doubtful that Boost.Thread is a problem. Anyway, just write a small test. First test. In one thread lots of iterations where you lock and unlock a `mutex` using `scoped_lock`. And then the second test. In a multithreaded test lock and unlock a mutex in different threads. And tell us about the outcome.
skwllsp