Coroutine Overview

The coroutine API is a basic implementation of a coroutine scheduling model, a lightweight non-preemptive multitasking mechanism.

A Cafe coroutine's non-volatile C state (the GPR, FPR, PSR registers, etc.) is saved in an OSCoroutine on a coroutine context switch. Coroutines are layered on top of COS threads. The OS thread scheduler does not know about coroutines.

The coroutine API is designed to help simplify the porting of older code that relies on an existing coroutine model. For example, existing Wii console applications that use the Wii OSSaveContext and OSLoadContext functions can be ported quickly by replacing these calls with the Wii U OSSaveCoroutine and OSLoadCoroutine functions, respectively.

A cooperating set of coroutines is restricted to a single thread on a single core. Another, distinct set of cooperating coroutines can use a different thread and core. But a coroutine in one of these sets may not switch to a coroutine in the other set.

The OSSwitchCoroutine function is more general, and its usage is preferred over OSSaveCoroutine and OSLoadCoroutine.

Although the Wii U coroutine API is not considered fully deprecated, it should not be used in new applications; threads should be used instead.

Coroutine API

OSInitCoroutine Initializes a coroutine.
OSLoadCoroutine Loads a previously saved coroutine, switching to it.
OSSaveCoroutine Saves the current coroutine's state.
OSSwitchCoroutine Switches from the current coroutine to a new one, saving the current coroutine's state.


Demos are available at the following locations.


Revision History

2013/08/02 Creation.