# Boost.Threads, lock_error
Keywords: threads, BTL, thread library, C++

###

# Boost.Threads

## lock_error

Introduction
Header
Synopsis
Members
Example

## Introduction

The `lock_error` class defines an exception type thrown to indicate a locking related error has been detected. Examples of such errors include a lock operation which can be determined to result in a deadlock, or unlock operations attempted by a thread that does not own the lock.

## Header

    #include <boost/thread/thread.hpp>

## Synopsis

    namespace boost

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

## Members

### Constructor

        lock_error();

Constructs a `lock_error` object.

## Example Usage

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

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

The output is:

    thread lock error - deadlock occurred.

Revised 05 November, 2001

© Copyright William E. Kempf 2001 all rights reserved.