1

First of all lets get this out of the way. I am a beginner in Ada, and the reason that I want to be able to do this is because I would like to program a Priority Inversion.

I have included,

with Ada.Task_Identification; 

I have also made a task type:

task type tasktype1 is
      pragma PRIORITY (20);
      entry gotosleep; 
end tasktype1;

and I have declared a task:

High : tasktype1;

Now I would like to change the priority of the task "High" to some other priority.

I have tried writing:

High.Prority(1); 

where I would put it in the main's begin block.

and declared a Task_ID.

 A : Task_Id;

then tried to fetch the current task with A := Current_Task;

and then put Priority(3,A); in the mains begin instead.

Here is all of my code for reference:

with Ada.Text_IO, Ada.Integer_Text_IO, System, Ada.Task_Identification; 
use Ada.Text_IO, Ada.Integer_Text_IO; 

procedure Main is

task type tasktype1 is
      pragma PRIORITY (20);
      entry gotosleep; 
end tasktype1;

pragma PRIORITY (3);   -- This is the priority for the main program

High : tasktype1;

  A : Task_Id;

task body tasktype1 is
   begin

accept gotosleep do 
     Put("Cow is not sleeping"); 

 end gotosleep; 
end tasktype1;




begin

   A := Current_Task; 
    Priority(3, A); 

   Put_Line("This is an example of use of a task type");
   Put_Line("This is an example of use of a task type");
   Put_Line("This is an example of use of a task type");
   Put_Line("This is an example of use of a task type");
   Put_Line("This is an example of use of a task type");

end Main;
David
  • 45
  • 1
  • 2
  • 7
  • 2
    You can set task priorities at runtime using `Ada.Dynamic_Priorities. Set_Priority` - see [ARM D.5.1](http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-D-5-1.html) (note, there is no subprogram `Priority` with the profile you expect!) – Simon Wright Dec 08 '16 at 14:01

2 Answers2

0

See: http://www.adaic.org/resources/add_content/standards/05rm/html/RM-D-5-1.html


TLDR; (if you wish to set/get the priority for the current task)

  1. "with" the package to your Ada source:

    with Ada.Dynamic_Priorities;
    
  2. Call the Set_Priority procedure

    Ada.Dynamic_Priorities.Set_Priority(1);
    

If you wish to find out the current priority, you can call

Ada.Dynamic_Priorities.Get_Priority;
Glen
  • 83
  • 1
  • 4
0

First, concerning task priority, you must check your OS capability.

For example, on Linux or Solaris, you can use priority only as root user. Else, the OS give the same priority for each task, regardless of what you set in the code. On Windows, I did not check what is the tasking policy available, but by default I would say that all tasks have the same priority.

Once it is done, the solution below should work fine.

Okyn
  • 1
  • 1