Skip to main content

Posts

Showing posts from March, 2009

Timing Specifications Needed for a Real Time Language

A Good Real time Programming language should specify various timing specifications for the entities in the System. But none of the languages does this. Following are some of the specifications needed for a good real time programming language
Specify
the duration between two events is no longer than the specified maximum and no shorter than the specified minimum.
the maximum runtime for a particular task, if the run time is not met, then an exception is generated.
the absolute time at which a task is to begin.
how soon a message is to be received after it is sent
how soon after receipt a message must be processed by the receiving task
periodic scheduling of the task
maximum time allocated for a loop to execute
upper bounds on the size of dynamic data structures

How Priority is Assigned to Tasks in ADA

procedure PRIORITY is
task A
task body A is
pragma PRIORITY(5);
begin
end A;
task B
task body B is
pragma PRIORITY(2);
begin
end B;
task C
task body C is
pragma PRIORITY(1);
begin
end C;
begin
–Procedure body
end PRIORITY
The above ADA code shows that static Priority of A is higher than B and B Over C. If two tasks have same priority then, the order of preference will be taken randomly.

Example 2 – Tasking in ADA

task ALARM is
entry AWAKE;
task body ALARM is
begin
loop
select
accept AWAKE;
or
delay 50.0;
SIGNAL_ALARM;
end select;
end loop;
end ALARM;

The above code shows that whether an operator is awake or not. If the operator is awake, then the AWAKE button is pressed every 50 sec. if not, the after a delay of 50 seconds, an ALARM will be sounded indicating the operator is away or AWAKE button is not pressed.
If the operator pressing the AWAKE button at 0 seconds or even at 49 seconds, the SIGNAL_ALARM procedure wont be executed at all. because the AWAKE button should be pressed once every 50 sec.

Example 1 – Tasking in ADA

task SERVER is
entry TASK_A(A,B:float);
entry TASK_B(A,B:float);
task body SERVER is
begin
loop
select
accept TASK_A(A,B:float);
or
accept TASK_B(A,B:float);
or
terminate;
end select;
end loop;
end SERVER;

The above program implements a server which serves the two Queues TASK_A and TASK_B through the float variable A and B. The Server is running with a infinite loop so the server is always serving either of the two queues. if the both the queues are empty, then the SERVER task will terminate. if both the queues are full, then the task will take from any one of the queue at a random fashion.

Multitasking in ADA

How multitasking is achieved in ADA. Please look at the following pseudo code

Procedure ABC
task A  
task body A is
——-
End A
task B
task body B is
——-
End A
task C  
task body Cis
——-
End C
Begin
–  Procedure ABC's statements
End ABC

In the above code, when the procedure begins all the three tasks A,B and C initiated concurrently and when the procedure ends, all the tasks completes their execution.  The three tasks does not have any relation with one another (means all are independent tasks)

Suppose if the tasks are having some relations between each other, then the following code depicts their behavior.
Procedure SHARING
Task A;
Task Body A is
B.BETA(X);
C.GAMMA(X);
End A;
Task B is
                Entry BETA(X:float);
Task Body B is
                Accept BETA(X:float);
End B;
Task C is
                Entry GAMMA(X:float);
Task Body C is
                Accept GAMMA(X:float);
End C;
Begin
End SHARING;

In the above code, the task A wants to share a float variable X at a point ALPHA with the tasks B and C at the po…