C++ Boost

Boost.Threads

lock_error


The lock_error class defines an exception type that is thrown by lock operations that would deadlock or unlock operations performed by a thread that does not own the lock.

Header

#include <boost/thread/thread.hpp>

Public Interface

    class lock_error : public std::runtime_error
    {
    public:
       lock_error();
    };

Constructor

    lock_error();

Constructs a lock_error.

Example Usage

#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <iostream>

int main(int, char*[])
{
    boost::mutex mutex;
    boost::mutex::lock lock(mutex);
    try
    {
       boost::mutex::lock deadlock(mutex);
       std::cout << "lock succeeded" << std::endl;
    }
    catch (boost::lock_error& err)
    {
       std::cout << err.what() << " - deadlock occurred." << std::endl;
    }
}

The output is:

thread lock error - deadlock occurred.

Copyright William E. Kempf 2001 all rights reserved.