Table of Contents

Multithreading on retrocomputers

FOREWORD: FROM THREADS TO PROTOTHREADS

In computer science, multithreading means the support in the execution of multiple “threads” or flows of execution. In systems with severe memory constraints such as computers based on 6502/6510 processors, traditional multi-threading can cause excessive memory overhead. In traditional multi-threading, in fact, each thread requires its own stack which, in turn, occupies large parts of the available memory.

Thanks to some specific features of the C language, it is possible to build a scheduler that allow you to implement a similar but lighter functionality of threads: the protothreads 1). The purpose of the protothreads is to implement a sequential flow of control without implementing complex finite state automata and without necessarily falling into the case of full multi-threading.

Protothreads are extremely light (each one requires only two bytes of memory to run), they are stackless, and provide (semantic) context to an event-based system. Being stackless makes them particularly useful in those contexts where speed is of the essence and space occupation is critical.

Protothreads are implemented in pure C and do not require any machine specific assembler code. They can therefore be used on all platforms that support the C compiler and, consequently, also in those supported by the MIDRES library.

This article will show you how to use them with MIDRES library, and their application on "The Elevator" game.

INDEX

1)
this article will illustrate how to use the functionality exposed by the primitives of MIDRES library; these primitives are strongly inspired by the protothreads library written by Adam Dunkels with the support of Oliver Schmidt, to whom reference should be made for further information