Nana C++ Library  

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

Description

The class recursive_mutex provides an exclusive_ownership recursive mutex.

Model of

None

Public base classes

None

Typedefs

native_handle_type  The type of native handle.

Members

recursive_mutex() The construction.
~recursive_mutex() The destruction.
void lock() Acquires the ownership for the calling thread.
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, An example

nana::threads::recursive_mutex mutex;
std::size_t n;

void inc()
{
    mutex.lock();
    ++n;
    mutex.unlock();
}

void thread1()
{
    inc();
}

void thread2()
{
    mutex.lock();
    for(int i = 0; i < 50; ++i)
        inc();
    mutex.unlock();
}

int main()
{
    //start thread1
    //start thread2

    //wait for threads.
}

See also

None.


Move to The Nana Programmer's Guide Main Page