-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpassing_data.tex
28 lines (21 loc) · 1.17 KB
/
passing_data.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\abschnitt{passing data between fibers}
Data can be transferred between two fibers via global pointer, a calling
wrapper (like \cpp{std::bind}) or lambda capture.
\cppfl{passing_lambda}
The \resume call at line 8 enters the lambda and passes 1 into the
new fiber. The value is incremented by one, as shown at line 4. The expression
\cpp{caller.resume()} at line 5 resumes the original context (represented
within the lambda by \cpp{caller}).
The call to \cpp{lambda.resume()} at line 10 resumes the lambda, returning from
the \cpp{caller.resume()} call at line 5. The \fiber instance \cpp{caller}
emptied by the \resume call at line 5 is replaced with the new instance
returned by that same \resume call.
Finally the lambda returns (the updated) \cpp{caller} at line 6, terminating its
context.
Since the updated \cpp{caller} represents the fiber suspended by the call at
line 10, control returns to \main.
However, since fiber \cpp{lambda} has now terminated, the updated \cpp{lambda}
is empty. Its \opbool returns \false.
\zs{Using lambda capture is the preferred way to transfer data between two
fibers; global pointers or a calling wrapper (such as \cpp{std::bind}) are
alternatives.}