previous | start | next

Coroutines

It may be desirable for an executing thread to give up the processor to allow another thread to execute.

It might do this by calling a function: thread_yield(). Another thread executes and may itself call thread_yield() causing the first thread to execute again returning from its call to thread_yield().

The threads are not calling each other, as they are mostly independently executing. But this transfer of control is known as coroutine execution.

Which other thread executes when thread_yield() is called?

How is control (i.e. the processor) transferred to the other thread?



previous | start | next