User Tools

Site Tools


mt6502:midres
Translations of this page:


Multithreading on retrocomputers

HOW ARE THEY IMPLEMENTED IN THE MIDRES LIBRARY?

Protothreads are implemented with macros that represent “annotations”, using so-called “local continuations”. Furthermore, they can also be used independently of MIDRES' graphic primitives.

A “local continuation” represents the current execution state at a particular point in the program, but does not provide any call history or local variables. You can set a local continuation in a specific function to capture the state of the function. Once a local continuation has been set it can be used to restore the function “state” to the point where the local continuation was set.

Local continuations can be implemented in various ways:

  • using “machine specific” assembler code;
  • using standard C constructs, or
  • using compiler “extensions”.

In the implementation on the MIDRES library, the standard C language option has been chosen, which requires only two bytes of status for protothread and uses the C “switch” instruction in a non-obvious way. The counterpart is the inability to use the switch statement in the code.

To learn more, see the protothreads library written by Adam Dunkels with the support of Oliver Schmidt.

Move to index.