-
Notifications
You must be signed in to change notification settings - Fork 2
Examples
David Dight edited this page Sep 20, 2023
·
26 revisions
The project includes over 30 examples. Most of the features of fiber
are demonstrated, some with various versions showing the different nuances that
are possible.
The following table summarises the examples.
Name | Description |
---|---|
fibertest.cpp |
Creates various fibers using different types of callable objects with custom stacks and parameters. Prints the fibers and prints the sizes of all the fiber objects. |
fibertest0.cpp |
Creates a single fiber, runs it and prints the yield/resume points; also demonstrates passing an object by reference to be modified by a fiber. |
fibertest1.cpp |
Similar to fibertest0 except fiber is a base class to a user object. |
fibertest2.cpp |
Demonstrates using a std::promise with a std::future to obtain a return value from a fiber; also demonstrates catching an exception when trying to obtain the value twice. |
fibertest3.cpp |
Uses a std::packaged_task to create a task returning a value. The task is passed to a fiber, run and the value is obtained from the task's std::future . |
fibertest4.cpp |
Uses async to create and run a fiber. A std::future is used to obtain the return value. |
fibertest5.cpp |
Passes a std::promise to a callable object. Throws and handles a test exception, passed back to the caller. |
fibertest6.cpp |
Presents one of the examples based on Dilawar's Blog. |
fibertest7.cpp |
Presents another example based on one from Dilawar's Blog. |
fibertest8.cpp |
Demonstrates the use of resume_with where a fiber's stack is completely overwritten with a new fiber. |
fibertest9.cpp |
Creates fibers using a class derived from fiber, passing fiber_params to a constexpr ctor. |
fibertest10.cpp |
Uses four detached fibers to construct a sentence from arrays of words. |
fibertest11.cpp |
Uses four fibers to construct a sentence from arrays of words with enforced ordering, showing the use of skipmain . |
fibertest12.cpp |
Demonstrates the difference between launch_all and launch_all_with_params using fibers to construct two sentences from arrays of words without and with enforced ordering. |
fibertest13.cpp |
Demonstrates suspending and unsuspending a fiber. |
fibertest14.cpp |
Shows the use of an arbitrary request token to signal a fiber to quit; uses verbose dtor. |
fibertest15.cpp |
Another example of an arbitrary request token to signal a fiber to quit; uses verbose dtor. |
fibertest16.cpp |
Creates 1000 fibers that generate 1-1000 random numbers and print the results. |
fibertest17.cpp |
Creates 10 fibers that generate a random amount of random numbers and print the results. |
fibertest18.cpp |
Creates 5 std::packaged_tasks of detached fibers calculating random numbers returned in a std::future ; these numbers are added together and printed. |
fibertest19.cpp |
Creates 12 fibers with varying stack types. |
fibertest20.cpp |
Demonstrates moving a fiber between threads. |
fibertest21.cpp |
A more complex example showing moving fibers between threads. |
fibertest22.cpp |
A class based generator using fibers with class members. |
fibertest23.cpp |
A class based generator using fibers with lambdas. |
fibertest24.cpp |
Another example showing moving fibers between threads. |
fibertest25.cpp |
Example showing the difference between using fiber and jfiber (CLI option selected). |
fibertest26.cpp |
A message reader that will suspend reading if insufficient data is available; shows a method to recover reader exceptions. |
fibertest27.cpp |
Demonstrates the difference between launch_all_n and launch_all_with_params_n using fibers to construct two sentences from arrays of words without and with enforced ordering. |
fibertest28.cpp |
A different approach to fibertest0.cpp
|
fibertest29.cpp |
Demonstrates using wait_all , wait_any and kill_all . |
fibertest30.cpp |
Generate a fibonacci series of any length and type using a detached fiber. |
fibertest31.cpp |
Another example creating fibers using a class derived from fiber, passing fiber_params to a constexpr ctor. |
fibertest32.cpp |
Example demonstrating various scenarios using different fiber types, exception handling and so forth. Designed for experimentation. |
utest01.cpp |
Main set of unit tests using Catch2 test framework. |
utest02.cpp |
Additional set of unit tests using Catch2 test framework. |
runall |
A script that runs all the above examples and unit tests. |
montest1.cpp-montest2.cpp |
Examples using the built-in monitor. |