Call Stack
You will learn the working of a call stack in this lesson.
We'll cover the following
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.
Call stack
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 main()
calling foo()
and foo()
calling bar()
:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy