Nana C++ Library  

An open-source C++ framework project
The Programmer's Guide 
nana::threads::lock_guard<typename Mutex>

Description

The class lock_guard maintains the ownership of a mutex object through the lock_guard's object lifetime.

Model of

None

Public base classes

None

Template Parameters

Mutex The type of a mutex object.

Typedefs

mutex_type The alias type of Mutex.

Members

explicit lock_guard(menu_type& m) Locks the mutex. If the mutex object is a non-recursive mutex, it might throw a std::runtime_error if the mutex is obtained the ownership.
~lock_guard() Unlocks the mutex.

File

nana/threads/mutex.hpp

Notes

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


nana::threads::recursive_mutex mtx;

void thread()
{
    using namespace nana::threads;
    lock_gaurd<mutex> lock(mtx);

    //Synchronized
}

int main()
{
    thread();
}

See also

None.


Move to The Nana Programmer's Guide Main Page