The Ada Rendezvous

Ada [Reference Manual for Ada Programming Language, US DoD, Nov 1980] is now the preferred language for software for US Defense contractors. It is designed to provide good Data Abstraction, in an Object Oriented way; what is relevant for this chapter is the tasking and inter-process communication paradigms available in Ada. In Ada, the normal set of modularizing definitions are available, including the facility to ;SPM_quot;package;SPM_quot; a number of procedures/functions together, with a separate public declaration, and private definition/implementation. As well as this, a module, like a package, can be declared as a <#372#> task<#372#>. A task is a unit of activity and tasks can be executed concurrently. The activation of tasks is defined by scope. Nested task declarations are children of some main task, and are activated when the main parent task begins as in figure #fnada1#373>.

#figure374#
Figure: Use of Tasks

The Ada language includes a synchronisation facility called the rendezvous. The rendezvous allows arbitrary processes to synchronise with each other and exchange data at that point. Somewhere in the <#377#> task<#377#> specification, there is one or more <#378#> entry<#378#> declarations. These are analogous to procedure (method) declarations in a package (class). There is a corresponding <#379#> accept<#379#> statement which contains the declaration of the executable statements that implement this entry. The <#380#> accept<#380#> and corresponding call to this rendezvous are <#381#> strongly<#381#> synchronized. This means that the called task is suspended at an <#382#> accept<#382#> until the caller calls this entry. The caller is then suspended until the called task completes execution of the end of the accept statement/block. The <#383#> entry<#383#> and call can pass in, out and in-out parameters. In this sense it is analogous to a remote procedure call (RPCs are discussed later in this chapter). Its use is illustrated in figure #fnada2#384>.

#figure385#
Figure: Use of Rendezvous

Two active processes are proceeding with their execution. In a symmetric way, whichever reaches the rendezvous first, waits. When both reach the rendezvous, a single transaction takes place. The transaction is exclusive so that consistency problems are avoided. The second example is rather artificial. It would almost certainly deadlock unless events arrived strictly alternately from the mouse and keyboard - an extremely unlikely situation. It is possible to schedule the rendezvous with delays and priorities. By default, some notion of fair scheduling is expected. A <#388#> select<#388#> statement allows a task to choose from one of several possible rendezvous. The <#389#> select<#389#> may be ;SPM_quot;guarded;SPM_quot; by a <#390#> when<#390#> clause. We can solve the problem in the last example, and even improve it by introducing priorities to make sure that mouse events are dealt with more promptly that keyboard ones (this is reasonable when a fast tracked mouse might traverse several hundred pixels in the time it takes to type a character). This is illustrated in #fnada3#391>.

#figure392#
Figure: Guards and Priorities