Boost Thread has the following: http://www.boost.org/doc/libs/1_58_0/doc/html/thread/synchronization.html#thread.synchronization.with_lock_guard
You can use it as you would expect:
std::mutex mx;
boost::with_lock_guard(mx, []{
});
INVOKE:
int foo(int,double) { return 42; }
int answer = boost::with_lock_guard(mx, foo, 3, 3.14);
:
template <typename M, typename F, typename... Args>
auto my_with_lock_guard(M& mx, F&& f, Args&&... args) {
std::lock_guard<M> lk(mx);
return std::forward<F>(f)(std::forward<Args>(args)...);
}
- , .