Task Control

Up to ten tasks can execute concurrently within a NXT user program. The ‘main’ or ‘primary’ task is automatically started when a user program is run. Execution of other tasks can be started and stopped with the ‘StartTask’ and ‘StopTask’ functions. The NXT will share CPU execution time among various tasks by giving each task a “time slice” where it will execute a group of instructions.

Each task can be assigned a priority from 0 to 255. The NXT scheduler gives execution time to the highest priority task that is waiting to run. A round robin scheduling scheme is used when there are multiple tasks ready to run all with the highest priority. Lower priority tasks will not execute until there are no tasks of higher priority that are ready to run.

A task that is waiting for a time period to expire is not ready to run. Once the time period has expired it will again become ready to run. Waiting tasks do not consume any CPU cycles.

 

nSchedulePriority

Variable containing the priority of the current task.

 

kDefaultPriority

Constant. The default priority assigned to a task.

 

kHighPriority

Constant. Highest priority that can be assigned to a task.

 

kLowPriority

Constant. Lowest priority that can be assigned to a task.

 

nCurrentTask

The numeric value for the current task.

 

nOpcodesPerTimeslice    

Used to specify the size of an execution time slice before switching to another task. User should not normally have to modify this variable.

 

StartTask(TaskID);

Starts or restarts execution of the specified task.

 

StopAllTasks();

Stops execution of the current program.

 

StopTask(TaskID);

Stops execution of a single task.

 

EndTimeslice();         

Immediately ends the current task time slice and allows another task to be immediately scheduled and executed.