kasyauqi
kasyauqi

Reputation: 645

Coroutine vs Fiber difference clarification

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)?

Upvotes: 25

Views: 17063

Answers (1)

xlrg
xlrg

Reputation: 2109

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.

Upvotes: 48

Related Questions