Task priority control
Page 1 of 1

Author:  Atlantisbase [ Wed Oct 29, 2008 5:24 pm ]
Post subject:  Task priority control

I know that there exists nSchedulePriority but how do I use it to prioritize tasks. There is no information in the documentation regarding its usage or syntax, etc. Additionally, is it a variable or function or array; again the documentation fails to specify. :?:

Author:  tfriez [ Thu Oct 30, 2008 10:41 am ]
Post subject:  Re: Task priority control

Here's a small sample program I just threw together. It'll show you how to assign a new priority to a task, and also store the priority into a variable so you can see what it is.

The default task priority is '7'. You can assign priorities between 0 and 255.

task taskA()
  nSchedulePriority = 15; //Raising the Priority
  int pri_taskA = nSchedulePriority;

task taskB()
  nSchedulePriority = 5; //Lowing the Priority
  int pri_taskB = nSchedulePriority;

task main()
  int pri_main = nSchedulePriority;    //Defaults to Priority '7'

  StartTask(taskB); //This task won't run because it has lower priority than "Main"

Author:  Ford Prefect [ Thu Oct 30, 2008 3:48 pm ]
Post subject:  Re: Task priority control

I still don't understand the effects of nSchedulePriority.
Is the nSchedulePriority proportional to the time slice?

if you had 1 main with nSchedulePriority = 7;
and three tasks (1,2,3) with nSchedulePriority = 14, 28, 56;
what effect will that have?

task1 2x time slice as main?
task2 4x time slice as main?
task3 8x time slice as main?

Author:  tfriez [ Thu Oct 30, 2008 4:29 pm ]
Post subject:  Re: Task priority control

Nope, it's just a way of classifying tasks by numeric priorities...

The CPU scheduler priority for the current task. ROBOTC shares 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 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.

So if the difference is 1 or 200, the higher task will use up all of the CPU time until the task is stopped or until a "wait" statement is used, allowing other lower priority threads to run. The numbers do not correspond to a proportion of priority.

It is critical that you use wait-statements when doing multitasking and your various other tasks do not need every millisecond of processing time (like waiting for a sensor to respond), otherwise the CPU will be hogged by that one task.

Author:  Ford Prefect [ Thu Oct 30, 2008 4:53 pm ]
Post subject:  Re: Task priority control

ok, thx.

Author:  Atlantisbase [ Sat Nov 01, 2008 6:29 pm ]
Post subject:  Re: Task priority control

Thank you for clearing up how to set task priority. The documentation does not provide much clarity on how to actually implement prioritization. I would suggest looking at the MSDN Library for ideas on how to organize the documentation.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group