pthread_mutex_lock __pthread_mutex_lock_full:断言失败,具有鲁棒性和0x40
pthread_mutex_lock __pthread_mutex_lock_full: Assertion failed with robust and 0x4000000
我正在处理一个服务器端项目,该项目应该接受100多个客户端连接。
它是使用boost::thread的多线程程序。有些地方我使用boost::lock_guard<boost::mutex>
来锁定共享的成员数据。还有一个包含输入连接的CCD_ 2。BlockingQueue
:的实现
template <typename DataType>
class BlockingQueue : private boost::noncopyable
{
public:
BlockingQueue()
: nblocked(0), stopped(false)
{
}
~BlockingQueue()
{
Stop(true);
}
void Push(const DataType& item)
{
boost::mutex::scoped_lock lock(mutex);
queue.push(item);
lock.unlock();
cond.notify_one(); // cond.notify_all();
}
bool Empty() const
{
boost::mutex::scoped_lock lock(mutex);
return queue.empty();
}
std::size_t Count() const
{
boost::mutex::scoped_lock lock(mutex);
return queue.size();
}
bool TryPop(DataType& poppedItem)
{
boost::mutex::scoped_lock lock(mutex);
if (queue.empty())
return false;
poppedItem = queue.front();
queue.pop();
return true;
}
DataType WaitPop()
{
boost::mutex::scoped_lock lock(mutex);
++nblocked;
while (!stopped && queue.empty()) // Or: if (queue.empty())
cond.wait(lock);
--nblocked;
if (stopped)
{
cond.notify_all(); // Tell Stop() that this thread has left
BOOST_THROW_EXCEPTION(BlockingQueueTerminatedException());
}
DataType tmp(queue.front());
queue.pop();
return tmp;
}
void Stop(bool wait)
{
boost::mutex::scoped_lock lock(mutex);
stopped = true;
cond.notify_all();
if (wait) // Wait till all blocked threads on the waiting queue to leave BlockingQueue::WaitPop()
{
while (nblocked)
cond.wait(lock);
}
}
private:
std::queue<DataType> queue;
mutable boost::mutex mutex;
boost::condition_variable_any cond;
unsigned int nblocked;
bool stopped;
};
对于每个Connection
,都有一个ConcurrentQueue<StreamPtr>
,它包含输入Streams。ConcurrentQueue
:的实现
template <typename DataType>
class ConcurrentQueue : private boost::noncopyable
{
public:
void Push(const DataType& item)
{
boost::mutex::scoped_lock lock(mutex);
queue.push(item);
}
bool Empty() const
{
boost::mutex::scoped_lock lock(mutex);
return queue.empty();
}
bool TryPop(DataType& poppedItem)
{
boost::mutex::scoped_lock lock(mutex);
if (queue.empty())
return false;
poppedItem = queue.front();
queue.pop();
return true;
}
private:
std::queue<DataType> queue;
mutable boost::mutex mutex;
};
调试程序时,它是可以的。但在具有50、100或更多客户端连接的负载测试中,有时会因而中止
pthread_mutex_lock.c:321: __pthread_mutex_lock_full: Assertion `robust || (oldval & 0x40000000) == 0' failed.
我不知道发生了什么,也不可能每次都重现。
我在谷歌上搜索了很多,但没有运气。请告知。
谢谢。
Peter
0x40000000
是FUTEX_OWNER_DIED
,它在futex.h
标头中有以下文档:
/*
* The kernel signals via this bit that a thread holding a futex
* has exited without unlocking the futex. The kernel also does
* a FUTEX_WAKE on such futexes, after setting the bit, to wake
* up any possible waiters:
*/
#define FUTEX_OWNER_DIED 0x40000000
因此,这个断言似乎表明持有锁的线程出于某种原因正在退出——有没有一种方法可以在线程对象持有锁时销毁它?
另一件需要检查的事情是,你是否有某种内存损坏。Valgrind可能是一个可以帮助你的工具。
我也遇到了类似的问题,并找到了这篇文章。这可能对你们中的一些人有用:在我的情况下,我只是错过了init。
pthread_mutex_init(&_mutexChangeMapEvent, NULL);
相关文章:
- 如何在没有死锁和/或争用的情况下正确使用 std::mutex C++?
- 尝试构建"lock-free"数据结构C++
- std::mutex 如何防止线程修改?
- 为什么 c++11 std::lock 和 std::scoped_lock 至少需要 2 个参数?
- DRD 报告"conflicting load" std::mutex::lock 上的错误
- std::lock_guard 怎么可能比 std::mutex::lock() 更快?
- std::mutex::lock() 产生奇怪(和不必要的)ASM 代码
- 在任何地方对C++中所有并行线程中的所有锁定和解锁实例使用相同的 std::mutex 和 lock 对象
- 使用Mutex,lock_guard,在课堂中正确地lock
- 当我调用lock()时,为什么std :: mutex会引发异常
- mutex.lock vs unique_lock
- mutex::lock() 检查一次解锁状态是否已经被另一个线程锁定?
- “std::mutex”和“std::lock”是否保证处理器间代码中的内存同步
- "mutex"和"lock"有什么区别?
- std::mutex::lock可以抛出即使一切看起来"good"?
- 什么是更好的 std::lock_guard<std::mutex> lock(std::mutex mutex_var); 或 std::mutex mutex_var.lock();
- std::lock_guard<std::mutex> lock(m) 是否有简写?
- 是否有任何惯用的显式使用mutex::lock()或unlock()
- PThread Mutex Lock & Unlock on Stack
- std::mutex::lock在Windows上失败,错误码3