2 (C) Copyright 2012 Vicente J. Botet Escriba.
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt).
8 [section:tutorial Tutorial]
11 [@http://web.archive.org/web/20140531071228/http://home.roadrunner.com/~hinnant/mutexes/locking.html Handling mutexes in C++] is an excellent tutorial. You need just replace std and ting by boost.
14 [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2406.html Mutex, Lock, Condition Variable Rationale] adds rationale for the design decisions made for mutexes, locks and condition variables.
17 In addition to the C++11 standard locks, Boost.Thread provides other locks and some utilities that help the user to make their code thread-safe.
19 [include internal_locking.qbk]
21 [include external_locking.qbk]
23 [section:with Executing Around a Function]
25 In particular, the library provides a way to lock around the execution of a function.
27 template <class Lockable, class Function, class... Args>
32 ) -> decltype(func(boost::forward<Args>(args)...)) {
33 boost::lock_guard<Lockable> lock(m);
34 return func(boost::forward<Args>(args)...);
37 that can be used with regular functions:
43 int result = boost::with_lock_guard(m, func, 1, boost::ref(a));
47 int result = boost::with_lock_guard(
48 m, boost::bind(func, 2, boost::ref(a))
51 or with lambda expression:
54 int result = boost::with_lock_guard(
57 // this scope is protected by mutex m
66 [endsect] [/ Tutorial]