]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/coroutine2/doc/coroutine.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / coroutine2 / doc / coroutine.qbk
1 [/
2 Copyright Oliver Kowalke 2014.
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:coroutine Coroutine]
9
10 __boost_coroutine__ provides asymmetric coroutines.
11
12 Implementations that produce sequences of values typically use asymmetric
13 coroutines.
14 [footnote Moura, Ana Lucia De and Ierusalimschy, Roberto.
15 "Revisiting coroutines". ACM Trans. Program. Lang. Syst., Volume 31 Issue 2,
16 February 2009, Article No. 6]
17
18
19 [heading stackful]
20 Each instance of a coroutine has its own stack.
21
22 In contrast to stackless coroutines, stackful coroutines allow invoking the
23 suspend operation out of arbitrary sub-stackframes, enabling escape-and-reenter
24 recursive operations.
25
26
27 [heading move-only]
28 A coroutine is moveable-only.
29
30 If it were copyable, then its stack with all the objects allocated on it
31 would be copied too. That would force undefined behaviour if some of these
32 objects were RAII-classes (manage a resource via RAII pattern). When the first
33 of the coroutine copies terminates (unwinds its stack), the RAII class
34 destructors will release their managed resources. When the second copy
35 terminates, the same destructors will try to doubly-release the same resources,
36 leading to undefined behaviour.
37
38
39 [heading clean-up]
40 On coroutine destruction the associated stack will be unwound.
41
42 The constructor of coroutine allows you to pass a customized ['stack-allocator].
43 ['stack-allocator] is free to deallocate the stack or cache it for future usage
44 (for coroutines created later).
45
46
47 [heading segmented stack]
48 __push_coro__ and __pull_coro__ support segmented stacks (growing on demand).
49
50 It is not always possible to accurately estimate the required stack size - in
51 most cases too much memory is allocated (waste of virtual address-space).
52
53 At construction a coroutine starts with a default (minimal) stack size. This
54 minimal stack size is the maximum of page size and the canonical size for signal
55 stack (macro SIGSTKSZ on POSIX).
56
57 At this time of writing only GCC (4.7)
58 [footnote [@http://gcc.gnu.org/wiki/SplitStacks Ian Lance Taylor, Split Stacks in GCC]]
59 is known to support segmented stacks. With version 1.54 __boost_coroutine__
60 provides support for segmented stacks.
61
62 The destructor releases the associated stack. The implementer is free to
63 deallocate the stack or to cache it for later usage.
64
65
66 [heading context switch]
67 A coroutine saves and restores registers according to the underlying ABI on
68 each context switch (using __boost_context__).
69
70 Some applications do not use floating-point registers and can disable preserving
71 FPU registers for performance reasons.
72
73 [note According to the calling convention the FPU registers are preserved by
74 default.]
75
76 On POSIX systems, the coroutine context switch does not preserve signal masks
77 for performance reasons.
78
79 A context switch is done via __push_coro_op__ and __pull_coro_op__.
80
81 [warning Calling __push_coro_op__ and __pull_coro_op__ from inside the [_same]
82 coroutine results in undefined behaviour.]
83
84 As an example, the code below will result in undefined behaviour:
85
86 boost::coroutines2::coroutine<void>::push_type coro(
87 [&](boost::coroutines2::coroutine<void>::pull_type& yield){
88 coro();
89 });
90 coro();
91
92
93 [include asymmetric.qbk]
94
95 [endsect]