Concepts of Programming Languages

(Sean Pound) #1

594 Chapter 13 Concurrency


is waiting for a message at the time task B sends that message, the message can
be transmitted. This actual transmission of the message is called a rendezvous.
Note that a rendezvous can occur only if both the sender and receiver want it to
happen. During a rendezvous, the information of the message can be transmit-
ted in either or both directions.
Both cooperation and competition synchronization of tasks can be conve-
niently handled with the message-passing model, as described in the following
section.

13.6 Ada Support for Concurrency


This section describes the support for concurrency provided by Ada. Ada 83
supports only synchronous message passing.

13.6.1 Fundamentals


The Ada design for tasks is partially based on the work of Brinch Hansen and
Hoare in that message passing is the design basis and nondeterminism is used
to choose among the tasks that have sent messages.
The full Ada tasking model is complex, and the following discussion of
it is limited. The focus here will be on the Ada version of the synchronous
message-passing mechanism.
Ada tasks can be more active than monitors. Monitors are passive entities
that provide management services for the shared data they store. They provide
their services, though only when those services are requested. When used to
manage shared data, Ada tasks can be thought of as managers that can reside
with the resource they manage. They have several mechanisms, some determin-
istic and some nondeterministic, that allow them to choose among competing
requests for access to their resources.
The syntactic form of Ada tasks is similar to that of Ada packages. There
are two parts—a specification part and a body part—both with the same name.
The interface of a task is its entry points, or locations where it can accept mes-
sages from other tasks. Because these entry points are part of its interface, it is
natural that they be listed in the specification part of a task. Because a rendez-
vous can involve an exchange of information, messages can have parameters;
therefore, task entry points must also allow parameters, which must also be
described in the specification part. In appearance, a task specification is similar
to the package specification for an abstract data type.
As an example of an Ada task specification, consider the following code,
which includes a single entry point named Entry_1, which has an in-mode
parameter:

task Task_Example is
entry Entry_1(Item : in Integer);
end Task_Example;
Free download pdf