A fiber is a thread of execution that enables a single thread to achieve multiple tasks. Compared to regular threads that are commonly used in parallelism and concurrency, it is more efficient to switch between fibers. Fibers are similar to coroutines and green threads.
Fibers enable multiple call stacks per thread. Therefore, to fully understand and appreciate fibers, one must first understand the call stack of a thread.
The parameters, non-static local variables, return values, and temporary expressions of a function, as well as any additional information that may be needed during its execution, comprise the local state of that function. The local state of a function is allocated and initialized automatically at run time every time that function is called.
The storage space allocated for the local state of a function call is called a frame (or stack frame). As functions call other functions during the execution of a thread, their frames are conceptually placed on top of each other to form a stack of frames. The stack of frames of currently active function calls is the call stack of that thread.
For example, once the main thread of the following program starts executing the
bar() function, there would be three levels of active function calls due to