pthread_mutex_lock __pthread_mutex_lock_full:声明由于健壮和0x4000000而失败 [英] pthread_mutex_lock __pthread_mutex_lock_full: Assertion failed with robust and 0x4000000

查看:860
本文介绍了pthread_mutex_lock __pthread_mutex_lock_full:声明由于健壮和0x4000000而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个服务器端项目,该项目应该接受100多个客户端连接.

I'm working on a server-side project, which is supposed to accept more than 100 client connections.

它是使用boost :: thread的多线程程序.我在某些地方使用boost::lock_guard<boost::mutex>锁定共享成员数据.还有一个BlockingQueue<ConnectionPtr>,其中包含输入连接. BlockingQueue:

It's multithreaded program using boost::thread. Some places I'm using boost::lock_guard<boost::mutex> to lock the shared member data. There is also a BlockingQueue<ConnectionPtr> which contains the input connections. The implementation of the 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>,其中包含输入流. ConcurrentQueue:

For each Connection, there is a ConcurrentQueue<StreamPtr>, which contains the input Streams. The implementation of the 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个或更多客户端连接的负载测试中,有时它会因

When debugging the program, it's okay. But in a load testing with 50 or 100 or more client connections, sometimes it aborted with

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.

我用Google搜索了很多,但是没有运气.请告知.

I googled a lot, but no luck. Please advise.

谢谢.

彼得

推荐答案

0x40000000FUTEX_OWNER_DIED-在futex.h标头中具有以下文档:

0x40000000 is FUTEX_OWNER_DIED - which has the following docs in the futex.h header:

/*
 * 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?

要检查的另一件事是您的某处是否存在某种内存损坏. Valgrind可能是一个可以帮助您的工具.

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.

这篇关于pthread_mutex_lock __pthread_mutex_lock_full:声明由于健壮和0x4000000而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆