CS452 - Real-Time Programming - Spring 2010

Lecture 31 - Ada

Public Service Announcements

  1. Due date for Tracking 2
  2. Project plan
  3. Evaluation
  4. Final Exam

Real-time Scheduling

Mixing an asynchronous interface with cyclic execution.

The easiest way to program a cell phone

  1. A collection of simple tasks that do things like

    running under cyclic execution.

  2. A user interface running asynchronously in a cyclically scheduled slice

Ada: One Language to Rule them All

The 1970s was the era of the universal computer language.

Ada was intended to be one

Over-all structure


task T is
    ....   // public face of task
end T; 
task body T is
    ....   // any code at all
end T;

Tasks are created by the declaration of a task variable

X: T;

Main program is implicitly called as a task.


Static type safety is an^H^Hthe over-riding concern.

Tasks can include

  1. Entries in their specifications
    task T is
        entry E( <in & out parameters> );
    end T;
  2. Accept statements that implement the entries
    accept E( <formal parameters> ) do
       ...  //code to be executed
    end E;
  3. Calls to entries in other tasks
    T.E( <actual parameters> );

Accept blocks until the call to the entry occurs.

The call blocks until the accept is executed.

Relationship to S/R/R

How do You Write a Server


    accept Send( request ) do
        // process request
        // fill in return parameters
    end Send;
end loop;

What's wrong here?

Here is one of the work-arounds.

        SendNotifier( data ) do
            // update internal state
        end SendNotifier;
        SendClient( request ) do
            // fulfil request
        end SendClient;
    end select;
end loop

How does this still fall short?

Is it possible to write a server in a programming language with nested scoping?


Pretty easy. Two time primitives

You can build delay from delay until, but not vice versa.


An interrupt handler is a parameterless procedure, that can be attached (either statically, at compile time, or dynamically, at run-time) to the occurrence of an interrupt.


  1. How would you attach interrupts to hardware that varies from execution to execution?
    task body Int is
            accept Interrupt do
                // manipulate device
                SendServer( error, data )
            end Interrupt
         end loop
    end Int
  2. Where and how do interrupts get turned on?
  3. How does the device get initialized?

Notice how device-specific the above code is.

`The Ada programming language defines the semantics of interrupt handling as part of the tasking mechanism, making it possible to construct implementation-independent interrupt handlers. However, for the Ada mechanism to be effective, an implementation must provide support not specified by the Ada standard, such as for initializing hardware interrupting devices, handling unexpected interrupts and optimizing for real-time performance constraints. This paper analyses some of the constraints that efficient interrupt support places on an implementation. It develops a model for the interaction between interrupt hardware and Ada tasks and describes optimizations for Ada interrupt handlers. Implementation issues, including task priorities and task termination for interrupt handlers, are discussed in detail.' Real-time interrupt handling in Ada Jørgen Born Rasmussen, Bill Appelbe, Software Practice and Experience.

Return to: