{{htmlmetatags>metatag-robots=()
metatag-title=(Multithreading on retrocomputers)
metatag-keywords=(Multithreading,Commodore 64,Commodore VIC20,Atari,Commodore128,MIDRES Library,6502,6510)
metatag-description=(How to implement fast and efficient multithreading on computers with limited resources.)
metatag-media-og:image=(:mt6502yy.png)
metatag-og:title=(Multithreading on retrocomputers)
metatag-og:description=(How to implement fast and efficient multithreading on computers with limited resources.)
}}
====== 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.
{{ ::tutorial_protothread.png?nolink&400 |}}
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** ((this article will illustrate how to use the functionality exposed by the primitives of [[:midres_library|MIDRES library]]; these primitives are **strongly inspired** by the [[http://dunkels.com/adam/pt/|protothreads library]] written by Adam Dunkels with the support of Oliver Schmidt, to whom reference should be made for further information)). 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 [[:elevator|"The Elevator" game]].
\adsense\
===== INDEX =====
* [[:mt6502:defining|HOW TO DEFINE A PROTOTHREAD]]
* [[:mt6502:coordinate|COORDINATE THE PROTOTHREADS]]
* [[:mt6502:blocking|BLOCKING AND NON-BLOCKING FUNCTIONS]]
* [[:mt6502:locals|HOW TO MANAGE LOCAL VARIABLES]]
* [[:mt6502:helloworld|"HELLO WORLD" WITH TWO PROTOTHREADS]]
* [[:mt6502:walking|ANIMATIONS USING PROTOTHREADS]]
* [[:mt6502:midres|HOW ARE THEY IMPLEMENTED IN THE MIDRES LIBRARY?]]