7.5 Summary.
A quick summary of the task and rendezvous syntax might be useful. Firstly a task specification.
task Example(discriminant) is entry First_Entry; entry Second_Entry(Params); private entry Third_Example; end Example;
The example below is simply a brief overview and reminder of the syntax brought up in this chapter, it will not compile!
task body Example is declarations begin accept First_Entry do statements end First_Entry; loop select when expression => accept Second_Example do statements requeue Third_Example; end Second_Example; or delay 5.0; statements or terminate; else select triggering_alternative statements then abort statements end select; end select; end loop; accept Third_Example do statements end Third_Example; end Example;
The following is a brief review of protected types.
protected type Example(discriminant) is procedure proc_name ..; function func_name ..; entry entry_name ..; private data : data_type; end Example; protected body Example is entry entry_name when expression is declarations begin statements end entry_name; .. end Example;
The IPC package introduced in this chapter is taken from our example application and can be used wherever the built in facilities of tasks and protected types are not quite suitable. For example we spoke in chapter 5 about the use of our linked list package in Ada_Store.PoST.Input_Queue, well here is that package.
The input queue is used to sequence input from peripheral devices, the devices decode their input and construct a Message which is then stored in the input queue which the application reads. The body for this package is below.
We have used both a semaphore and a mutex in the above example. The mutex protects the input queue from concurrent access by multiple tasks, the semaphore allows the reader to block on either Peek or Get until an item is placed on the queue.
Another use of tasking is found in the keyboard device, a task Keyboard_Reader reads characters from the PC keyboard and handles echoing the characters to the screen.
The task above is quite simple, the main loop reads characters identifies characters which end a sequence and basically calls the keyboard device. The interesting point is that the task does not start reading characters the moment it is created, it has a rendezvous Start which must be called first. The Echo_Char procedure puts the character read from the keyboard on the display, and buffers up all characters until the End_Echo procedure is called. End_Echo then packages up the keys so far and interprets their meaning.
Copyright ©
1996 Simon Johnston &
Addison Wesley Longman