• Home
  • Textbooks
  • Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX
  • Message-based synchronization and communication

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

Alan Burns, Andy Wellings

Chapter 6

Message-based synchronization and communication - all with Video Answers

Educators


Chapter Questions

Problem 1

Given that Ada supports protected objects, should the Ada rendezvous facilities be removed from the language?

Check back soon!

Problem 2

If an Ada task has two entry points, is it possible for it to accept the entry of the calling task which has been waiting for the longest period of time?

Check back soon!

Problem 3

Show how to implement a binary semaphore using an Ada task and a rendezvous. What happens if a task issuing a Wai.t is aborted before it can issue a Signal?

Check back soon!

Problem 4

Discuss the advantages and disadvantages of implementing semaphores with a rendezvous rather than a protected object.

Check back soon!

Problem 5

Show how an Ada task and the rendezvous can be used to implement Hoare's monitors.

Check back soon!

Problem 6

To what extent can an Ada rendezvous be considered a Remote Procedure Call? Discuss the following code which purports to implement a particular remote procedure. Consider both the called procedure and the implications for the calling task.
task type Rpc_Implementation is
entry Rpc(Param1:Type1; Param2:Type2);
end Rpc_Implementation;
task body Rpc_Implementation is
begin
accept Rpc(Param1:Type1; Param2:Type2) do
-- body of procedure
end Rpc;
end Rpc_Implementation;
-- declare an array of 1000 rpc_implementation tasks
Concurrent_Rpc : $\operatorname{array}(1$.. 1000) of Rpc_Implementation;

Check back soon!
00:51

Problem 7

Complete Exercise 4.8 using the Ada tasks and the rendezvous.

Tanishq Gupta
Tanishq Gupta
Numerade Educator
04:18

Problem 8

Consider an Ada system of three cigarette smoker tasks and one agent task. Each smoker continually makes cigarettes and smokes them. To make a cigarette, three ingredients are required: tobacco, paper and matches. One of the smoker tasks has an infinite supply of paper, another has an infinite supply of tobacco and the third has an infinite supply of matches. The agent task has an infinite supply of all three ingredients. Each smoker task must communicate with the agent task to obtain the two ingredients it is missing.
task Agent is
entry Give_Matches (...) ;
entry Give_Paper (...) ;
entry Give_Tobacco (...) ;
entry Cigarette_Finished;
end Agent;

The body of the agent task chooses two ingredients randomly, and then accepts communication on the associated entries to pass the ingredients to the smokers. Once both ingredients have been passed, it waits for communication on the Cigarette_Finished entry before repeating the task indefinitely. A smoker, having received the required ingredients, makes and smokes a cigarette, indicates completion by calling the Cigarette_Finished entry and then requests new ingredients.
Sketch the specification and body of the three smoker tasks and the body of the agent task. If necessary, add parameters to the entry specifications of the Agent task. The solution should be deadlock-free.

Daniel Caproni
Daniel Caproni
Numerade Educator

Problem 9

A server task has the following Ada specification:
task Server is
entry Service_A;
entry Service_B;
entry Service_c;
end Server;
Write the body of the Server task so that it performs all of the following operations.
- If client tasks are waiting on all the entries, the task should service the clients in a cyclic order; that is, accept first a Service_A entry, and then a Service_B entry, and then a Service_C entry, and then a Service_A entry and so on.
- If not all entries have a client task waiting, the Server should service the other entries in a cyclic order. The server tasks should not be blocked if there are clients still waiting for a service.
- If the Server task has no waiting clients then it should NOT busy-wait; it should block waiting for a client's request to be made.
- If all the possible clients have terminated, the Server should terminate.
Assume that client tasks are not aborted and issue simple entry calls only.

Check back soon!

Problem 10

The following Ada package provides a service. During the provision of this service the exceptions A, B, C and D can be raised.
package Server is
A, B, C, D : exception;
procedure Service; -- can raise $A, B, C$ or $D$
end Server;
In the following procedure two tasks are created; task One rendezvous with task Two. During the rendezvous task, Two calls the Service provided by the server package.
with Server; use Server;
with Ada.Text_Io; use Ada.Text_Io;
procedure Main is
task One;
task Two is
entry Sync;
end Ivo;
task body one is
begin
Two.Sync;
exception
when $A \Rightarrow$
Put_Line("A trapped in one ");
raise;
when $B \Rightarrow$
Put_Line ("B trapped in one");
raise $C$;
when $\mathrm{C}=>$
Put_Line("C trapped in one");
when $\mathrm{D} \Rightarrow$
Put_Line("D trapped in one");
end;
task body Two is
begin -- block $X$
begin -- block $Y$
begin -- block Z
accept Sync do
begin
Service;
exception
when $\mathrm{A}=>$
Put_Line("A trapped in sync");
when $\mathrm{B} \Rightarrow$
Put_Line("B trapped in sync");
raise;
when $\mathrm{C}=>$
Put_Line ("C trapped in sync");
raise $D$;
end;
end Sync;
exception
when $\mathrm{A} \stackrel{\rightharpoonup}{\mathrm{a}}$
Put_Line ("A trapped in block Z");
when $\mathrm{B}=>$
Put_Line ("B trapped in block Z") ;
raise $\mathrm{C}$;
when others $=>$
Put_Line("others trapped in $\mathrm{Z"}$ );
raise $C$;
end; -- block Z
exception
when $\mathrm{C}=>$
Put_Iine ("C trapped in $\mathrm{Y}$ ");
when others $=>$
Put Line("others trapped in $\mathrm{Y}$ ");
raise $\mathrm{C}$;
end; -- block $Y$
exception
when $\mathrm{A} \quad \Rightarrow$
Put_Line ("A trapped in X") ;
when others $\Rightarrow$
Put_Line("others trapped in X");
end; -- block $X$ and task TWO
begin -- procedure main
nul1;
exception
when $\mathrm{A} \Rightarrow>$
Put_Line("A trapped in main");
when $\mathrm{B} \Rightarrow$
Put_Line("B trapped in main");
when $\mathrm{C} \Rightarrow$
Put_Line("C trapped in main");
when $\mathrm{D} \Rightarrow$
Put__Line ("D trapped in main");
end Main;

The procedure Put_Line is declared in the package Text_Io, and when called it prints its argument on the terminal.
What output would appear if the Service procedure:
(1) raised exception $\mathrm{A}$ ?
(2) raised exception $B$ ?
(3) raised exception $\mathrm{C}$ ?
(4) raised exception $D$ ?

Assume that output does not become intermingled by concurrent calls to Put_Line.

Check back soon!