August 2017
Intermediate to advanced
438 pages
14h 19m
English
boost::make_unique_locks and boost::lock functions may accept more than 2 locks or mutexes, so you could use them in more advanced cases, where more than two mutexes must be locked simultaneously.
C++11 has a std::lock function defined in the header <mutex> that behaves exactly like the boost::lock function.
C++17 has a much more beautiful solution:
#include <mutex>void user::exchange_loot(user& u) { std::scoped_lock l(loot_mutex_, u.loot_mutex_); loot_.swap(u.loot_);}
In the preceding code, std::scoped_lock is a class that accepts a variadic amount of locks. It has variadic template parameters that are automatically deduced from the C++17 deduction guide. The actual type of the std::scoped_lock from the preceding example ...
Read now
Unlock full access