1. Overview of boost locks:
The boost Library provides the mutex and lock classes. By combining them, you can easily build read/write locks and mutex locks.
2. mutex object class (two main types ):
1. boost: mutex (exclusive mutex class) --> There are lock and unlock methods
2. boost: shared_mutex (shared mutex class) --> There are lock And unlock methods And shared_lock And shared_unlock methods.
3. lock template class:
1. boost: unique_lock <T> (exclusive lock): T in unique_lock <T> can be any of the mutex classes. The lock and unlock methods are automatically called.
2. boost: shared_lock <T> (shared lock): The T in shared_lock <T> can only be shared_mutex class; The shared_lock and shared_unlock methods are automatically called.
4. Recursive mutex:
Boost: mutex: scoped_lock
Boost: mutex io_mutex;
Void foo ()
{
{
Boost: mutex: scoped_lock lock (io_mutex); // lock
} // Unlock
}
5. Set lock timeout:
Boost: unique_lock <boost: timed_mutex> lk (io_mutex, std: chrono: milliseconds (3); // timeout for 3 seconds