task type
declares a task type. The value of an object of a task type designates a task having the entries, if any, that are declared in the task specification; these entries are also called entries of this object. The execution of the task is defined by the corresponding task body.
type
defines a single task. A task declaration with this form of specification is equivalent to the declaration of an anonymous task type immediately followed by the declaration of an object of the task type, and the task unit identifier names the object. In the remainder of this chapter, explanations are given in terms of task type declarations; the corresponding explanations for single task declarations follow from the stated equivalence.
task_specification ::=
task
[type
] identifier [is
{entry_declaration}
{representation_clause}
end
[task_simple_name]]
task body
task_simple_name is
[declarative_part]
begin
sequence_of_statements
[exception
exception_handler
{exception_handler}]
end
[task_simple_name];
task type
RESOURCE is
entry
SEIZE;
entry
RELEASE; end
RESOURCE; task type
KEYBOARD_DRIVER is
entry
READ (C : out
CHARACTER);
entry
WRITE(C : in
CHARACTER);
end
KEYBOARD_DRIVER;
task
PRODUCER_CONSUMER is
entry
READ (V : out
ITEM);
entry
WRITE(E : in
ITEM);
end
; task
CONTROLLER is
entry
REQUEST(LEVEL)(D : ITEM); -- a family of entries end
CONTROLLER; task
USER; -- has no entries
task
PROTECTED_ARRAY is
-- INDEX and ITEM are global types
entry
READ (N : in
INDEX; V : out
ITEM);
entry
WRITE(N : in
INDEX; E : in
ITEM);
end
; task body
PROTECTED_ARRAY is
TABLE : array
(INDEX) of
ITEM := (INDEX => NULL_ITEM);
begin
loop
select
accept
READ (N : in
INDEX; V : out
ITEM) do
V := TABLE(N);
end
READ;
or
accept
WRITE(N : in
INDEX; E : in
ITEM) do
TABLE(N) := E;
end
WRITE;
end select
;
end loop
;
end
PROTECTED_ARRAY;