View unanswered posts | View active topics It is currently Sat Nov 01, 2014 2:16 am






Reply to topic  [ 6 posts ] 
Task priority control 
Author Message
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post 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. :?:

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Wed Oct 29, 2008 5:24 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 613
Post 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.

Code:
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(taskA);
  StartTask(taskB); //This task won't run because it has lower priority than "Main"
}

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Oct 30, 2008 10:41 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Oct 30, 2008 3:48 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 613
Post Re: Task priority control
Nope, it's just a way of classifying tasks by numeric priorities...

Quote:
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.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Oct 30, 2008 4:29 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Task priority control
ok, thx.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Oct 30, 2008 4:53 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post 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.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Sat Nov 01, 2008 6:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.