Concepts of Programming Languages

(Sean Pound) #1
13.6 Ada Support for Concurrency 601

loop
-- produce New_Value --
Buf_Task.Deposit(New_Value);
end loop;
end Producer;

task body Consumer is
Stored_Value : Integer;
begin
loop
Buf_Task.Fetch(Stored_Value);
-- consume Stored_Value --
end loop;
end Consumer;

13.6.4 Task Termination


The execution of a task is completed if control has reached the end of its code
body. This may occur because an exception has been raised for which there is
no handler. Ada exception handling is described in Chapter 14. If a task has not
created any other tasks, called dependents, it is terminated when its execution
is completed. A task that has created dependent tasks is terminated when the
execution of its code is completed and all of its dependents are terminated. A
task may end its execution by waiting at an open terminate clause. In this
case, the task is terminated only when its master (the block, subprogram, or
task that created it) and all of the tasks that depend on that master have either
completed or are waiting at an open terminate clause. In that case, all of these
tasks are terminated simultaneously. A block or subprogram is not exited until
all of its dependent tasks are terminated.

13.6.5 Priorities


A task can be assigned a priority in its specification. This is done with a pragma,^3
as in
pragma Priority(static expression);
The static expression is usually either an integer literal or a predefined con-
stant. The value of the expression specifies the relative priority for the task or
task type definition in which it appears. The possible range of priority values is
implementation dependent. The highest priority possible can be specified with
the Last attribute, the priority type, which is defined in System (System
is a predefined package). For example, the following line specifies the highest
priority in any implementation:

pragma Priority(System.Priority'Last);


  1. Recall that a pragma is an instruction for the compiler.

Free download pdf