Skip to content

rithreadlib

This library runs a piece of the program as a thread: a DOS process of its own that runs at the same time as the main program. CreateThread starts the code at a label, given with ?label; the code ends with RTS, and the thread ends with it. ActiveThreads tells how many threads are still running. When the program ends, it waits for its threads to end first.

A thread shares the program’s global variables, so the main program and its threads can talk through them; it gets 10 KB of cleared working memory of its own, which is freed when the program ends. The library needs Kickstart 2.0 or later, and works in Amiga mode only.

DEFTYPE .l count
CreateThread "counter",?counter
While ActiveThreads>0
  Delay_ 5
Wend
NPrint count
End

counter:
For i=1 To 1000 : count=count+1 : Next
RTS

The fixed bugs of the library are listed in Fixes in rithreadlib.

Library number 44.

Commands

ActiveThreads

The number of threads started with CreateThread that have not ended yet.

Function, result .w. No help text.
No arguments.

Amiga mode only.

When the program ends, it waits until no thread runs any more.

CreateThread

Starts the code at address (a label given with ?label, ending with RTS) as a new DOS process called name, which runs alongside the program.

Statement. Help text: name,address
Arguments: $, .l

Amiga mode only. The command returns at once, before the thread has started to run. The thread shares the program’s global variables and gets 10 KB of cleared working memory of its own. Each thread runs its own code with its own memory, also when several CreateThread follow each other before the first thread has begun to run. A thread that cannot be started, for lack of memory, is not counted.