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]
10 [@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.
12 [@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.
15 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.
17 [include internal_locking.qbk]
19 [include external_locking.qbk]
21 [section:with Executing Around a Function]
23 In particular, the library provides a way to lock around the execution of a function.
25 template <class Lockable, class Function, class... Args>
30 ) -> decltype(func(boost::forward<Args>(args)...)) {
31 boost::lock_guard<Lockable> lock(m);
32 return func(boost::forward<Args>(args)...);
35 that can be used with regular functions:
41 int result = boost::with_lock_guard(m, func, 1, boost::ref(a));
45 int result = boost::with_lock_guard(
46 m, boost::bind(func, 2, boost::ref(a))
49 or with lambda expression:
52 int result = boost::with_lock_guard(
55 // this scope is protected by mutex m
64 [endsect] [/ Tutorial]