There are 3 thin threads with manual low-latency context switching in the Boost:
What is the difference between Coroutine1, Coroutine2 and Fiber in Boost?
Fibers (sometimes called stackful coroutines or user mode cooperatively scheduled threads) and stackless coroutines (compiler synthesized state machines) represent two distinct programming facilities with vast performance and functionality differences.
Coroutines are very similar to threads. However, coroutines are cooperatively multitasked, whereas threads are typically preemptively multitasked. Coroutines provide concurrency but not parallelism.
Fiber provides a framework for micro-/userland-threads (fibers) scheduled cooperatively. The API contains classes and functions to manage and synchronize fibers similiarly to standard thread support library.
Boost. Coroutine provides templates for generalized subroutines which allow multiple entry points for suspending and resuming execution at certain locations. It preserves the local state of execution and allows re-entering subroutines more than once (useful if state must be kept across function calls).
boost.coroutine is non-C++11 and therefore requires to use a private API from boost.context (reason because it is deprecated).
boost.coroutine2 and boost.fiber require C++11 and use callcc()/continuation (implements context switch, call-with-current-continuation) from boost.context.
boost.coroutine and boost.coroutine2 implement coroutines, while boost.fiber provides fibers (== lightweigt, coroperative userland-threads, green-threads, ...) with an API similar to std::thread.
The difference between coroutines and fibers is described in N4024: Distinguishing coroutines and fibers - in short: fibers are switched by an internal scheduler while coroutines use no internal scheduler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With