Chapter 9. Tasks

Syntax:


      TASK identifier [ '(' parameter list ')' ] IS
        statement_block
      END TASK
    

JALv2 introduces the concept of TASKs which are a form of co-operative multi-tasking. Unlike preemptive multi-tasking, where control passes from one task to another automatically, control will only pass when a task specifically allows it. Due to the architecture of a PIC, true multi-tasking is very difficult. Tasks can only be started by the main program, or within another task. Tasks are started with:


      START identifier [ '(' parameter list ')' ]
    
When a task is ready to allow another to run, it executes:

      SUSPEND
    
To end the task, simply RETURN or allow the control to pass to the end of the task. If tasks are used, the compiler must be passed the argument, "-task n," where n is the number of concurrent running tasks. Remember that the main program itself is a task, so if you plan to run the main program plus two tasks, you'll need to pass in, "-task 3".

Finally, only one copy of the body of a task should be run at a time. The following would be an error because it attempts to run two copies of task1 at the same time:


      START task1
      START task2

      FOREVER LOOP
        SUSPEND
      END LOOP