Multitasking: The main loop

Our multitasking scheme uses one of the simplest possible program structures (short of ad hoc spaghetti code, which has no structure at all!). We call it "A main loop calling individual tasks as subroutines". If that sounds like an indigestible bowl of something other than spaghetti, fear not, all shall become clear!

Consider the following program fragment:

MainLoop
         GoSub     FlashTheLight
         GoSub     OnOffSwitch
         GoSub     RingTheBell
         GoTo      MainLoop

This code loop will call each of the 3 subroutines in turn, and repeatedly, in quick succession. Well, it will be in quick succession providing none of the subroutines keeps SPLatty tied up indefinitely or even for an undue amount of time.

That proviso is the crux of the matter. If we can structure each subroutine so it never, ever, ever monopolizes the processor (SPLatty), then we will have created an illusion of 3 things going on at once. That means:

That means some aspects of FastTrack programming can no longer be used. FastTrack, after all, is there to make it easy for newbies to get useful results quickly. Now it's time to get rid of the trainer wheels and move on. In the next section we'll start looking at ways and means of building subroutines that are free of such instructions and structures.

Special note: This tutorial and the multitasking mechanism it covers have largely been superseded by the newer MultiTrack mechanism. MultiTrack achieves everything and more, with considerably less programming effort. The only time you would use this older multitasking mechanism would be if the controller you are using is unable to handle as many tasks as you need using MultiTrack.