comp.lang.ada
 help / color / mirror / Atom feed
* Priority Ceiling
@ 2003-07-23 21:24 Stephan Heinemann
  2003-07-23 22:19 ` Robert I. Eachus
  0 siblings, 1 reply; 2+ messages in thread
From: Stephan Heinemann @ 2003-07-23 21:24 UTC (permalink / raw)


Please have a look at the following piece of code:

pragma Queuing_Policy(Priority_Queuing);
pragma Locking_Policy(Ceiling_Locking);
pragma Task_Dispatching_Policy(FIFO_Within_Priorities);

with System; use System;
with Ada.Dynamic_Priorities; use Ada.Dynamic_Priorities;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Priorities is
    pragma Priority(0);
    -- if not specified default priority is inherited by tasks?
    P1: constant Priority := Priority'First;
    P2: constant Priority := Priority'Last;

    protected Ceiling_Object is
        --pragma Priority(System.Priority'Last);
        pragma Priority(2);
        -- less than 15 raises Program_Error?
        -- default priority
        procedure E;
    end Ceiling_Object;

    protected body Ceiling_Object is    
        procedure E is
        begin
            Put_Line("E entered");
            -- delay 5.0; -- should actually not be done
            -- display the active priority
            Put(Image(Current_Task));
            Put(Get_Priority(Current_Task)); New_Line;
            -- dynamic priority not raised?
            Put_Line("E finished");
        end E;
    end Ceiling_Object;
    
    task A is
        pragma Priority(0);
    end A;
    
    task body A is
    begin
        Put_Line("T running");
        Ceiling_Object.E;
        -- should raise Program_Error only if task priority
        --- higher than ceiling priority
        Put_Line("T done");
    exception
        when Ex: others =>
            Put(Image(Current_Task) & " ");
            Put(Exception_Name(Ex)); New_Line;
    end A;
    
    task B is
        pragma Priority(1);
    end B;
    
    task body B is
    begin
        Put_Line("B running");
        Ceiling_Object.E;
        Put_Line("B done");
    exception
        when Ex: others =>
            Put(Image(Current_Task) & " ");
            Put(Exception_Name(Ex)); New_Line;
    end B;

begin
    Put("P1: "); Put(P1); New_Line;
    Put("P2: "); Put(P2); New_Line;
end Priorities;

Now the questions:
(1)
If I understood correctly then the task priority should be raised to the
ceiling priority of the protected object (immediate ceiling priority
protocol). However, I cannot obtain this new active priority using
"Get_Priority(Current_Task)"; the base priority is returned instead. Why?
(2)
The procedure "Priorities" would run with default priority (15) if
pragma Priority(0) was not given. But this change seems to affect the
defined tasks as well, eventhough they have their own base priorities
assigned to them. Do they inherit their priorities from the
"Priorities"-executing task, if they are assigned lower base priorities
than the latter?

Thanks in advance,
Stephan



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-07-23 22:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-23 21:24 Priority Ceiling Stephan Heinemann
2003-07-23 22:19 ` Robert I. Eachus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox