[英]pthread_mutex_lock __pthread_mutex_lock_full: Assertion failed with robust and 0x4000000
I'm working on a server-side project, which is supposed to accept more than 100 client connections.我正在做一个服务器端项目,它应该接受超过 100 个客户端连接。
It's multithreaded program using boost::thread.它是使用 boost::thread 的多线程程序。 Some places I'm using
boost::lock_guard<boost::mutex>
to lock the shared member data.有些地方我使用
boost::lock_guard<boost::mutex>
来锁定共享成员数据。 There is also a BlockingQueue<ConnectionPtr>
which contains the input connections.还有一个包含输入连接的
BlockingQueue<ConnectionPtr>
。 The implementation of the BlockingQueue
: 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;
};
For each Connection
, there is a ConcurrentQueue<StreamPtr>
, which contains the input Streams.对于每个
Connection
,都有一个ConcurrentQueue<StreamPtr>
,其中包含输入流。 The implementation of the ConcurrentQueue
: 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;
};
When debugging the program, it's okay.调试程序的时候,没问题。 But in a load testing with 50 or 100 or more client connections, sometimes it aborted with
但是在具有 50 或 100 或更多客户端连接的负载测试中,有时它会中止
pthread_mutex_lock.c:321: __pthread_mutex_lock_full: Assertion `robust || (oldval & 0x40000000) == 0' failed.
I have no idea what happened, and it cannot be reproduced every time.我不知道发生了什么,也不能每次都重现。
I googled a lot, but no luck.我用谷歌搜索了很多,但没有运气。 Please advise.
请指教。
Thanks.谢谢。
Peter彼得
0x40000000
is FUTEX_OWNER_DIED
- which has the following docs in the futex.h
header: 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
So the assertion seems to be an indication that a thread that's holding the lock is exiting for some reason - is there a way tha a thread object might be destroyed while it's holding a lock? 因此断言似乎表明持有锁的线程由于某种原因而退出 - 是否有一种方法可以在线程对象持有锁时被销毁?
Another thing to check is if you have some sort of memory corruption somewhere. 要检查的另一件事是你是否在某处有某种内存损坏。 Valgrind might be a tool that can help you with that.
Valgrind可能是一个可以帮助你的工具。
I had a similar issue and found this post.我遇到了类似的问题并找到了这篇文章。 It may be useful for some of you: in my case I was just missing the init.
它可能对你们中的一些人有用:在我的例子中,我只是缺少 init.
pthread_mutex_init(&_mutexChangeMapEvent, NULL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.