comp.lang.ada
 help / color / mirror / Atom feed
* (Newbie) intertask communication
@ 2001-04-06 17:37 Pieter Thysebaert
  2001-04-06 20:46 ` Mark Lundquist
  0 siblings, 1 reply; 2+ messages in thread
From: Pieter Thysebaert @ 2001-04-06 17:37 UTC (permalink / raw)


Hi....

I'm trying to have two tasks interact (using entry/accept).
In fact we have this assignment where we are supposed to (not in reality)
monitor some patient's heartbeat.

So I created two task types : patient and monitor

The idea is that the patient will call the function (entry) beat on his/her
associated monitor;
the monitor will accept beat() calls and will display a warning when not
receiving  a heartbeat for two (or x) seconds

So this is my monitor:

task body monitortask is
   id : Integer;
begin
   accept start(patient_id : Integer) do
     id := patient_id;
   end;
   loop
      select
         accept beat do
             PutLine(<patient id is alivestuff>);
         end;
      or
          delay 2;
          sound_alarm();
   end loop;

end monitortask;

And the patient :

task body patienttask is
begin
   accept start(m : monitortask) do
   loop
      delay <random value between 1 and 4 seconds>;
      m.beat;
   end loop;
   end;
end patienttask;

My problem/question is : this stuff only works when m.start is called first
in a testprogram, end then p.start
(m : monitortask and p : patientask) - the testprogram blosk on the
patient.start thing
That's because I have the loop _IN_ the patient's accept statement.

Of course what I want is more like :


task body patienttask is
  mymonitor : monitortask;
begin
  accept start(m : monitortask) do
     mymonitor := m;
  end;
  loop
.....do stuff but call mymonitor.beat;


which will not block the testprogram calling p.start;

Unfortunately, the assignment to mymonitor does not work like this.

How would I pass the "name" of a task to antoher task to have it use that
one ?
And how can I save a "reference"to a task  ?


Pieter







^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-04-06 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-06 17:37 (Newbie) intertask communication Pieter Thysebaert
2001-04-06 20:46 ` Mark Lundquist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox