What is Yield in programming ?
In computer science, yield is an action that occurs in a computer program during multithreading, of forcing a processor to relinquish control of the current running thread, and sending it to the end of the running queue, of the same scheduling priority.
What is Cooperative multitasking ?
Cooperative multitasking, also known as non-preemptive multitasking, is a style of computer multitasking in which the operating system never initiates a context switch from a running process to another process. Instead, in order to run multiple applications concurrently, processes voluntarily yield control periodically or when idle or logically blocked. This type of multitasking is called cooperative because all programs must cooperate for the scheduling scheme to work.
Coroutine vs Subroutine
Each time a function is called execution moves to the start of that function, then continues until it reaches the end of that function (or a return statement), at which point execution moves back to the point immediately after the function call, any later calls to the function are independent calls which start again at the beginning.
Coroutines@1 are computations that support Cooperative multitasking@2. Unlike ordinary Subroutines that execute from start to end, and do not hold any state between invocations, coroutines can exit in the middle, and may resume later from the same point while holding state between invocations. They do so by yielding the control of the current running thread.
Subroutines are special cases of coroutines. Any subroutine can be translated to a coroutine which does not call yield.