24

In the book Linux System Programming, 2nd Edition, the difference between coroutines and fiber is explained as follows:

Coroutines and fibers provide a unit of execution even lighter in weight than the thread (with the former being their name when they are a programming language construct, and the latter when they are a system construct).

I have some example of Coroutines (language constructs) but unable to find the example of Fibers.

Can anyone provide me some example of Fiber (a system construct)?

kasyauqi
  • 635
  • 1
  • 6
  • 17

1 Answers1

45

You could take a look at boost.coroutine2 and boost.fiber (C++ libraries) - both use the same context switching mechanism (callcc()/continuation) from boost.context.

In short - the difference between coroutines and fibers is, that the context switch between fibers is managed by a scheduler (selects the next fiber ...). Coroutines don't have a concept of a scheduler.

A more detailed explanation of the difference between coroutines and fibers can be read in N4024: Distinguishing coroutines and fibers.

xlrg
  • 1,994
  • 1
  • 16
  • 14