4

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.

  • Have you read the [GNAT User Guide](https://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn/the_gnat_compilation_model.html#the-configuration-pragmas-files)? – egilhh Jun 11 '21 at 22:22
  • I have not read it in detail cover to cover, if that's what you mean. I take it it's a suggestion rather than an answer. But, in fact, I have answered my own question in the mean time, indeed by using some thing from https://www.cs.fsu.edu/~baker/ada/gnat/html/gnat_ugn_10.html – Dan Winslow Jun 11 '21 at 22:36
  • Which is some version of the users guide. For those readers who would like the information, this pragma is expressed in a 'gnat.adc' file in the current compilation directory. So I made such a file, dropped the pragma in there, and it seems to compile, but does not appear to affect the actual compiled program. I may need some compilation switches or something. – Dan Winslow Jun 11 '21 at 22:42
  • Actually, it did change the frequency of task one and task two interleaving - it made task one run for a while exclusive, but still swapped over to two at some point, which than ran by itself for a while, and then swapped back to one, rather that the very frequent interleaving I was seeing before. Not quite what I am looking for yet. I expected to see one task start and the other never run. – Dan Winslow Jun 11 '21 at 22:48

1 Answers1

1

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045