tags:

views:

217

answers:

3

Can anyone supply me with simple working examples which illustrate the use of pragmas in Ada 2005 ? I understand that pragmas are used to priorities processes, just that I have not come across working examples !

Much appreciated !

+2  A: 

An Ada pragma is a language feature that allows adjusting or fine-tuning the behavior of an Ada program. A number of pragmas are defined by the Ada language standard, but compiler vendors can also define their own.

The subject of pragmas cover far more than just process [tasking] priorities, here's a list of standard and vendor-provided pragmas to check out.

What exactly are you trying to do with the aid of pragmas? Set task priorities?

-- Not compile checked:
with System; use System;

task Prioritized_Task is
   pragma Priority(System.Default_Priority + 1);

   entry Start;

end Prioritized_Task;
Marc C
Hi Marc ....I was planning to make a program which would print 5'A's 5'B's and 5'C's (3 jobs , each with a different priority) according their given order of priority as given by pragmas, and changing the pragmas would change their order of printing. This sort of an example would possibly exhibit the utility of pragmas.
Arkapravo
+2  A: 

As with much of Ada, I think the best answer here is really to consult the LRM. The section on managing task priorities is actually very readable, for a language standard definition anyway.

Note that you can also set the priority of a task at runtime without use of a pragma. This makes use of the package Ada.Dynamic_Priorities. This is what I typically do these days, unless for some weird reason the desired priority is known at compile time, and I don't mind hard-coding it.

I highly suggest that advanced users such as yourself poke through the LRM to see what all the language provides you. Pay particular attention to the annexes (the sections starting with a letter), as that is where most of the good stuff is documented. In your case, you will probably be particularly interested in the Real-Time annex (Annex D).

T.E.D.
Hi T.E.D, Thanks for your reply ! .... I have gone through LRM and lot of other stuff .... it is a pity that I yet do not have a 'simple working example' which illustrate that how pragmas can priorities a given set of task ...... I am particularly very interested in pragmas since otherwise, using semaphores the programming does become somewhat cumbersome ! ... If you have any simple illustrative working example then it will be a great help to me !
Arkapravo
+1  A: 

A search of comp.lang.ada for recent discussions about priorities has several interesting examples. This one seems particularly apropos to your question.

Addendum: Two other exemplary sources are the Rationale for Ada 95 and Rationale for Ada 2005

trashgod
Thanks trashgod , nice link !
Arkapravo
Excellent; it's an exemplary group, second only to the LRM. Please consider accepting one of the answers and possibly up-voting any that you found helpful.
trashgod
The last link is really only relevant if he is running under Linux. On Windows you don't need admin to change priority (although you do need it to hit the top priority levels, which could make the machine unresponsive if you go into a tight loop). Good to know though.
T.E.D.
@T.E.D.: Good point about variation among platforms.
trashgod
@T.E.D , @trashgod , dudes I am on Linux (Ubuntu Karmic 9.10) .... Windows sucks when it comes to coding ! ....
Arkapravo