Unlike coroutines, concurrent programming (threads) involve "simultaneous" execution. Simultaneous is quoted because, although at the programmer level you can think of the threads as executing simultaneously, in reality, on a non-threaded single processor machine this is not the case. The single processor is jumping back from thread to thread:
- - -
/ \
>---- - - - - ----->>
On multi-processor or on a threaded machine it really is simultaneous:
---
/ \
>-------------->>
For the typical application, you don't
need to worry about what the processor is doing.
Your job is to write a threaded algorithm only.
Start by downloading
this Ada program. You
job is modify it.
This Ada program is an example of concurrent programming using
Ada tasks. Tasks are similar to coroutines in that you have multiple
entry and exit points. But in addition to this, a task represents a separate
thread of control that can proceed independently and concurrently
between the points of interaction with the other tasks.
Refer to the documentation on Ada Tasks and Synchronization
as you work on this part of the lab. Make the following changes to lab09.adb:
Task #1. Add a data structure to the program to hold the names of the dogs. Each time you add a dog, its name is added to the structure. The structure can be as simple as an array of Strings. Caveat - due to strong constraint-checking, data types are never simple in Ada. You must do the following:
type Names is array(1..25) of String(1..5); -- array for dog names
subtype names_index is Integer range 1..25; -- the index into dog array
my_names : Names;
And later, if you assign a value to the array from a literal, the literal
MUST be of length 5.
my_names(names_index) := "Tiger";
Task #2. Add parameters to the message passing that occurs in between main program and the Kennel task. Message passing is at two entry points : dropoffDog and pickupDog. An example of adding parameters to messages is here:
TASK worker IS
ENTRY run (repeat : IN Integer; length : IN Integer);
END worker;
TASK BODY worker IS
..
ACCEPT run (repeat : IN Integer; length : IN Integer) DO
save_repeat := repeat;
save_length := length;
END run;
..
END worker;
Add two IN parameters to dropoffDog. One is a boolean. If this
parameter is true the dog is not a biter and safe to insert into the kennel.
If the dog is a biter then do not insert the dog.
The second parameter is a string containing the name of the dog.
If you insert the dog you need to add the dog's name to the String array.
Each time you display the Kennel, display the name of the dogs.