• Home
  • Textbooks
  • Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX
  • Atomic actions, concurrent tasks and reliability

Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX

Alan Burns, Andy Wellings

Chapter 7

Atomic actions, concurrent tasks and reliability - all with Video Answers

Educators


Chapter Questions

00:46

Problem 1

Distinguish between an atomic action and an atomic transaction. What is the relationship between an atomic transaction and a conversation?

David Collins
David Collins
Numerade Educator

Problem 2

Rewrite the Action_x Ada package given in Section 7.6.3 so that it becomes a general-purpose package for controlling a three-task conversation. (Hint: use generics.)

Check back soon!
00:26

Problem 3

Can your solution to Exercise 7.2 be extended to cope with an arbitrary number of tasks participating in the atomic action?

David Collins
David Collins
Numerade Educator

Problem 4

What would be the implications of extending Ada to enable one task to raise an exception in another?

Check back soon!

Problem 5

Compare and contrast asynchronous notification and exception handling.

Check back soon!
00:39

Problem 6

In Section 7.6.3, backward and forward error recovery is shown between three Ada tasks. Show how they can be combined into a single solution that gives both forward and backward error recovery between the same three tasks.

Maxime Rossetti
Maxime Rossetti
Numerade Educator

Problem 7

Update the solution given in Section 7.6.1 to deal with the deserter problem.

Check back soon!

Problem 8

Consider the following four fragments of code:
-- Fragment 1
select
T.Call; -- an entry call to task $T$
Flag : $=\mathrm{A}$;
or
delay 10.0;
Flag : $=$ B;
- code taking 2 seconds to execute
end select;
-- Fragment 2
select
T.Call; -- an entry call to task $T$
Flag : $=\mathrm{A}$;
else
delay 10.0;
Flag : $=\mathrm{B}$;
-- code taking 2 seconds to execute
end select;
-- Fragment 3
select
T.Call; -- an entry call to task $T$
Flag : $=\mathrm{A}$;
then abort
delay 10.0;
Flag : = B;
-- code taking 2 seconds to execute
end select;
-- Fragment 4
select
delay 10.0;
Flag : $=\mathrm{A}$;
then abort
T.Call; -- an entry call to task $T$
Flag : $=\mathrm{B}$;
-- code taking 2 seconds to execute
end select;
A rendezvous with T.Call takes 5 seconds to execute. What is the value of the Flag variable after the execution of each of the four fragments in each of the following cases? You may assume a Flag assignment statement takes zero execution time.
(1) T.Call is available when the select is executed.
(2) T.Call is NOT available when the select is executed and does not become available in the next 14 seconds.
(3) T.Call is NOT available when the select is executed, but does become available after 2 seconds.
(4) T.Call is NOT available when the select is executed but does become available after 8 seconds.

Check back soon!

Problem 9

Consider the following package specification which provides a procedure to search part of a large character array for a unique fixed-length string. The procedure returns the position of the start of the string if it is found.
package Search_Support is
type Array_Bounds is range 1 .. 1_000_000_000;
type Large_Array is array (Array_Bounds) of Character;
type Pointer is access Large_Array;
procedure Search(Pt: Pointer;
Lower, Upper: Array_Bounds;
Looking_For : Search_String;
Found : out Boolean;
At_Location : out Array_Bounds) ;
end Search_Support;
Three tasks wish to perform a concurrent search of the array for the same string; they are derived from a common task type.
task type Searcher(Search_Array: Pointer;
Lower, Upper: Array_Bounds) is
entry Find(Looking_For : Search_String) ;
entry Get_Result (At_Location : out Array_Bounds) ;
end Searcher;
The string to be found is passed via an initial rendezvous with the tasks. Sketch the body of the task type (and any other objects you might need) so that when one task finds the string, all other tasks are immediately informed of the string's location so that further fruitless search is avoided. Assume that the SearchString will be found by one of the three tasks. Furthermore, all tasks must be prepared to pass back the result via the Get Result entry.

Check back soon!

Problem 10

Consider the following Ada code fragment:
Error_1, Error_2 : exception;
task Watch;
task Signaller;
protected Atc is
entry Go;
procedure Signal;
private
Flag : Boolean := False;
end Atc;
protected body Atc is
entry Go when Flag is
begin
raise Error_1;
end Go;
procedure Signal is
begin
Flag : = True;
end Signal;
end Atc;
task body watch is
begin
...
select
Atc. Go;
then abort
-- code taking 100 millisecond
raise Error 2;
end select;
...
exception
when Error_1 $\Rightarrow$
Put_Line("Error_1 Caught");
when Error_2 =>
Put_Line("Error_2 Caught");
when others $\Rightarrow$
Put_Line("Other Errors Caught");
end watch;
task body Signaller is
begin
$+\cdots$
Atc. Signal;
...
end Signaller;
Describe carefully the possible executions of this program fragment assuming that context switches between tasks can happen at any time.

Check back soon!

Problem 11

A particular POSIX-based application consists of several periodic processes and has two modes of operation: MODE A and MODE B. The application has one process which only operates in MODE A. Sketch the design of this process assuming that when the system wishes to undertake a mode change, it sends a signal to all processes indicating the current mode of operation. Assume also the existence of a routine called WAITNEXTPERIOD, which will suspend the process until its next period of execution is due. Note that a mode change should only affect the process at the beginning of each period.

Check back soon!

Problem 12

Illustrate how Ada's OOP model can be used to produce extensible atomic actions.

Check back soon!

Problem 13

Compare and contrast the Ada and Java models for asynchronous transfer of control.

Check back soon!

Problem 14

To what extent can standard Java be used to implement atomic actions?

Check back soon!

Problem 15

Why have the Java routines resume (), stop () and suspend () been made obsolete?

Check back soon!

Problem 16

Redo Exercise 7.11 for Real-Time Java.

Check back soon!

Problem 17

Show how Ada's termination model of exception handling can be implemented in response to the receipt of a POSIX signal.

Check back soon!