[英]boost scoped_lock mutex crashes
我在這些函數中保護了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
謝謝您的幫助
x的值看起來很可疑。
它看起來模糊地類似於0xabababab,它可能是在調試模式下分配給內存的初始值,或者可能是保護值的一部分,用於指示分配的內存塊是否寫入超出結束或開始
你能追溯到那個價值來自哪里嗎?
我認為你沒有正確創建MyClass的實例。 就像一個未正確初始化的MyClass指針,然后以這種方式使用ptr->inboxSize()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.