Boost logo

Boost Users :

Subject: [Boost-users] Assertion `!pthread_mutex_destroy(&m)' failed.
From: Panagiotis Foteinos (pafotein_at_[hidden])
Date: 2011-03-25 15:58:21


Hello users.

I am new to boost:threads, so my apologies in advance.

I am getting an assertion failure right before main() exits. Specifically, I
get the following error: "*/usr/include/boost/thread/pthread/mutex.hpp:45:
boost::mutex::~mutex(): Assertion `!pthread_mutex_destroy(&m)' failed.*"

Below is the code snippet:

***********************************************************************************************************************************
class Test
{
private:
    boost::mutex mtx;

public:
    int counter;
    Test()
    {
        counter = 10;
    }
    void DoWork()
    {
        for(unsigned int i = 0; i < 1000000; i++)
        {
            mtx.try_lock();
            counter++;
            mtx.unlock();
        }
    }
};

int main()
{
    unsigned int N = 7;
    boost::thread* test_threads = new thread_type[N];
    for(unsigned int i = 0; i < N; i++)
    {
        test_threads[i] =
thread_type(boost::lambda::bind<void>(&Test::insert, &object));
    }

    for(unsigned int i = 0; i < N; i++)
    {
        test_threads[i].join();
    }

    return 1;
}
***********************************************************************************************************************************

Can somebody shed some light? Main() exits normally, if I replace
mtx.try_lock() with mtx.lock(). Why this behavior?

Best Regards,
Panagiotis Foteinos



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net