Nana C++ Library  

An open-source C++ framework project
The Programmer's Guide 
nana::threads::mutex

Description

The class mutex provides an exclusive ownership non-recursive mutex.

Model of

None

Public base classes

None

Typedefs

native_handle_type  The type of native handle.

Members

mutex() The construction.
~mutex() The destruction.
void lock() Acquires the ownership for the calling thread. If the calling thread have obtained the ownership, it throws a std::runtime_error to avoid the deadlock. (See Note 1)
bool try_lock() Attempts to obtain the ownership without blocking. If ownership is not obtained, it returns false.
void unlock() Relases the ownership of the calling thread.
native_handle_type native_handle() Returns the native handle.

File

nana/threads/mutex.hpp

Notes

1, Reacquires the ownership for a owned mutex, it throws the std::runtime_error to avoid a deadlock.

int main()
{
    nana::threads::mutex mutex;
    mutex.lock(); //Acquires the ownership.
    mutex.lock(); //It throws the std::runtime_error because the ownership is obtained.
}

See also

None.


Move to The Nana Programmer's Guide Main Page