Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Multitasking
Co-operative multitasking explained
Live website search
Enter key words
 

CO-OPERATIVE MULTITASKING EXPLAINED

Co-operative multitasking

Co-operative multitasking

Pre-emptive multitasking

Pre-emptive multitasking

The TDS2020F multitasker is pre-emptive by default, but can be changed to the traditional Forth co-operative style by adding the word UNSLICE after TASKS in the power-up word.

Co-operative Multitasking task changes are not made at a particular instant. This contrasts with the Pre-emptive Multitasking scheme where a change is forced if a task hogs the microprocessor for too long.

The file #ROBIN.TDS gives the Co-operative Multitasking traditionally associated with Forth. Tasks are linked in a circle, or round robin, with execution passing to the next one whenever the word PAUSE is reached. All details of the current task are stored and the next task in the round robin takes over. It continues until a PAUSE in its own code is reached, when the next task takes over and so on. If pre-emption has been turned off as shown above you will usually need to add PAUSE explicitly like this:

 

: TEST1

FRED ACTIVATE BEGIN 7 EMIT 500 MS PAUSE AGAIN ;

 

The word PAUSE is placed wherever you can allow a task change to take place and there must be at least one per loop of a task. Since PAUSE is already embedded in MS it is not strictly necessary in the example but is included for clarity.

When writing in assembler code the following does exactly the same as PAUSE and you can include it to move one step along the round robin of tasks:

 

DECIMAL

13 ## TRAPA, \ PAUSE this task and start next one

 

Do not overdo the use of PAUSE because it takes time to switch from one task to the next and this is unproductive use of the microprocessor. The time lost is 43�s (53�s from TDS2020DV).

PAUSE is already embedded in words which most of the time do no work like MS and KEY . It is also in TYPE so that you will get a task change at least once for every line of output. In addition you put PAUSE in the application program wherever you want, especially in loops that wait for something or take considerable time. Words containing PAUSE are the following, and any word dependent on these:

 

<KEY>  <PUT> PUT  AWAIT  HOME-CURSOR KEY

LCDEMIT  MS  NEWKEY  PRIME SHIFT  TYPE  WIPE

U.  U.R  . D.R  .R

Go to Triangle Digital Support Home Page Go to top   Next page