Usage example of pragma Task_Dispatching_Policy(Non_Preemptive_FIFO_Within_Priorities);

Viewed 132

I have a large, heavily task oriented program, and I would like to explore variant scheduler policies. I am using Gnat Ada 2020. In particular, I would like to set the tasking model by use of the pragma:

pragma Task_Dispatching_Policy(Non_Preemptive_FIFO_Within_Priorities);

I don't think I understand the actual usage very well. I understand what the pragma does, but I am having difficulty placing the pragma correctly, at least according to GNAT. For various combinations of placement in the following small program, I always get the error : "incorrect placement for configuration pragma "Task_Dispatching_Policy" I have tried outside of the whole compilation unit, within the task type spec, within the task body spec, etc. Can anyone show me an example of usage of this pragma? Googling found many discussions but no actual examples of usage in source code. Thanks in advance.

with Ada.Text_IO; Use Ada.Text_Io;
 
procedure Test is

   Task Type One is
   End;  

   Task Type Two;

   Task body One is
   Begin
     Loop
       Put_line("Task one 11111111111111111");
     End Loop;
   End;

   Task body Two is
   Begin
     Loop
       Put_line("Task two 2222222222222222");
     End Loop;
   End;

  a : One;
  B : two;
begin
  Null;
End;

As suggested below, I found something in the UG about placing the pragma in a 'gnat.adc' file, and that seemed to take effect but did not completely prevent the switching, which is what I expected. I should mention I am on a Windows 10 environment.

I consider this as answered by way of @egilhh's comment. Will be glad to accept his if he posts one I am able to accept on.

1 Answers

I am having difficulty placing the pragma correctly.

Focusing on correct placement, note that a Task_Dispatching_Policy pragma is a configuration pragma that must "appear before the first compilation_unit of a compilation."

at least according to GNAT.

As @egilhh comments, the GNAT User Guide describes how tp accomplish this in 3.4.1. Handling of Configuration Pragmas:

Configuration pragmas may either appear at the start of a compilation unit, or they can appear in a configuration pragma file to apply to all compilations performed in a given compilation environment.

In the case of a single compilation unit, simply place the pragma before the first context clause, as shown here:

pragma Task_Dispatching_Policy(…);
with Ada.Text_IO; use Ada.Text_IO;
…

To apply the pragma more broadly, add it to gnat.adc as described in §3.4.2. The Configuration Pragmas Files.

Related