An introduction by Dennis C. Bemmann
RoboCom Language Standard 3.00 introduces Multitasking. This allows a robot to do multiple things at once. By initializing a new task, the robot splits up its CPU resources and starts executing code at another point somewhere in its code so that each task can do a different thing. The priority is given to another task with each timecycle. Of course the tasks have to share the robot's CPU resources so that your program gets slower with each new task.
Initializes a new task in bank a, instruction b.
Ends the current task.
gives the current task 100% priority and pauses the other tasks until the current task executes a RESUME.
ends a SEIZE: the other tasks are unpaused and proceed normally. CPU resources are shared equally between all tasks.
ends all tasks but the current task.
NOTE how the SLEEP instruction works in Multitasking mode (see FAQ below).
Q: | Is there any overhead when using tasks? |
---|---|
A: | No. Every timecycle is given to a task. No cycles are used up just for the ABILITY of multitasking.
|
Q: | How do I use a label with INIT? |
A: | It's just like BJUMP: all labels in an INIT instruction are interpreted as absolute (i.e. the number of the instruction in the bank, not the relative distance). Thus you don't have to care where a label is declared. Example: INIT 5, @MyLabel |
Q: | When a task has 100% priority due to a SEIZE and it INITializes a new task, is the new task paused as well? |
A: | Yes, the new task is initialized but paused like all the others, until the current task executes a RESUME.
|
Q: | What happens if I try to INITialize a new task when the maximum number of tasks is already reached? |
A: | In this case INIT ends the oldest task which is not the current one and replaces it by the new task. If only one task is allowed in the options, INIT has no effect other than taking its usual time.
|
Q: | What happens if the last task executes a QUIT instruction? |
A: | The last task terminates itself and the robot dies of an "Unemployment error".
|
Q: | What happens if a SEIZEd task (with 100% priority) is ended? |
A: | The other tasks are unpaused and proceed normally after the current task is ended.
|
Q: | In what cases does a robot die and in what cases is just the current task ended? |
A: | If a DATA HUNGER occurs, just the current task is ended. The QUIT instruction also just ends the current task. However, if the last task is ended due to any reason, the robot dies. The robot also dies of any FATAL ERRORs, ELIMINATIONS and of executing the DIE instruction.
|
Q: | How does SLEEP work in Multitasking mode? |
A: | The SLEEP instruction causes the current task to wait the specified amount of timecycles before the next instruction is queued. SLEEP is actually not a multitasking-related instrucion, but while a robot sleeps it does not use up any timecycles. A sleeping task leaves all its CPU resources to the other tasks. The duration of a SLEEP is absolute - that means: the duration stays the same regardless of how many tasks there are. Even if a sleeping task is paused because another task calls the SEIZE instruction, this paused time counts for the SLEEP duration. However, the SLEEP instruction can only be finished after the task is resumed again (even if the SLEEP duration is exceeded by then).
|
Q: | Does each task have a separate #Active variable? |
A: | No! A robot has exactly one single #Active variable, so the robot as a whole can either
be active or inactive. This is the same concept as without multitasking and has nothing to
do with sleeping or paused tasks.
|