]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fiber/doc/rationale.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / fiber / doc / rationale.qbk
CommitLineData
7c673cae
FG
1[/
2 Copyright Oliver Kowalke 2013.
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
6]
7
8[section:rationale Rationale]
9
10[heading distinction between coroutines and fibers]
11
12The fiber library extends the coroutine library by adding a scheduler and
13synchronization mechanisms.
14
15* a coroutine yields
16* a fiber blocks
17
18When a coroutine yields, it passes control directly to its caller (or, in the
19case of symmetric coroutines, a designated other coroutine). When a fiber
20blocks, it implicitly passes control to the fiber scheduler. Coroutines have
21no scheduler because they need no scheduler.[footnote
22[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4024.pdf 'N4024:
23Distinguishing coroutines and fibers']].
24
25
26[heading what about transactional memory]
27
28GCC supports transactional memory since version 4.7. Unfortunately tests show
29that transactional memory is slower (ca. 4x) than spinlocks using atomics.
30Once transactional memory is improved (supporting hybrid tm), spinlocks will
31be replaced by __transaction_atomic{} statements surrounding the critical
32sections.
33
34
35[heading synchronization between fibers running in different threads]
36
37Synchronization classes from __boost_thread__ block the entire thread. In
38contrast, the synchronization classes from __boost_fiber__ block only specific
39fibers, so that the scheduler can still keep the thread busy running other
40fibers in the meantime.
41The synchronization classes from __boost_fiber__ are designed to be
42thread-safe, i.e. it is possible to synchronize fibers running in different
43threads as well as fibers running in the same thread. (However, there is a
44build option to disable cross-thread fiber synchronization support; see [link
45cross_thread_sync this description].)
46
47[#spurious_wakeup]
48[heading spurious wakeup]
49
50Spurious wakeup can happen when using
51[@http://en.cppreference.com/w/cpp/thread/condition_variable
52`std::condition_variable`]: the condition variable appears to be have been
53signaled while the awaited condition may still be false. Spurious wakeup can
54happen repeatedly and is caused on some multiprocessor systems where making
55`std::condition_variable` wakeup completely predictable would slow down all
56`std::condition_variable` operations.[footnote David R. Butenhof ["Programming
57with POSIX Threads]]
58
59__condition__ is not subject to spurious wakeup. Nonetheless it is
60prudent to test the business-logic condition in a `wait()` loop [mdash] or,
61equivalently, use one of the `wait( lock, predicate )` overloads.
62
63See also [link condition_variable_spurious_wakeups No Spurious Wakeups].
64
65
66[heading migrating fibers between threads]
67
68Support for migrating fibers between threads has been integrated. The
69user-defined scheduler must call __context_detach__ on a fiber-context on the
70source thread and __context_attach__ on the destination thread, passing the
71fiber-context to migrate. (For more information about custom schedulers, see
72[link custom Customization].)
73Examples `work_sharing` and `work_stealing` in directory `examples` might be
74used as a blueprint.
75
76See also [link migration Migrating fibers between threads].
77
78
79[heading support for Boost.Asio]
80
81Support for __boost_asio__[s] __async_result__ is not part of the official API.
82However, to integrate with a __io_service__, see [link integration Sharing a
83Thread with Another Main Loop]. To interface smoothly with an arbitrary Asio
84async I/O operation, see [link callbacks_asio Then There[s] __boost_asio__].
85
86[heading tested compilers]
87
88The library was tested with GCC-5.1.1, Clang-3.6.0 and MSVC-14.0 in c++11-mode.
89
90
91[heading supported architectures]
92
93__boost_fiber__ depends on __boost_context__ - the list of supported architectures
94can be found [@http://www.boost.org/doc/libs/release/libs/context/doc/html/context/architectures.html here].
95
96
97[endsect]