comp.lang.ada
 help / color / mirror / Atom feed
From: "W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM>
Subject: Re: Two-Way Task Communication In Ada (w/o Protected Objects)
Date: 1996/11/27
Date: 1996-11-27T00:00:00+00:00	[thread overview]
Message-ID: <9611271353.AA03732@most> (raw)


I don't recommend this, but if you MUST have two tasks communicating
WITHOUT any intermediates, here's an example:

task Guru is
  entry Listen ( Question : String );
end Guru;

task Novice is
  entry Listen ( Answer : String );
end Novice;

task body Novice is
begin
  Exist:
    loop
      Experiment;
      Scratch_Head;
      Guru.Listen ( Question => "Why does this happen?" );
      Do_Something_Else_While_The_Guru_Thinks;
      accept Listen ( Answer : String ) do
        Parse_Unconstrained_String_Somehow;
      end Listen;
      Scratch_Head;
    end loop Exist;
end Novice;

task body Guru is
begin
  Exist:
    loop
      select
        accept Listen ( Question : String ) do
          Store_Unconstrained_String;
        end Listen;
      else
        Meditate;
        if I_Feel_Like_Speaking then
          if Question_Is_Stored then
             Novice.Listen ( Answer => Incomprehensible_Remark
                                       ( Based_On => Unconstrained_String ) );
          else
             Novice.Listen ( Answer => Incomprehensible_Remark );
          end if;
        end if;
        Meditate;
      end select;
    end loop Exist;
end Guru;

--------

Why is it not recommended?  Well, it may very well run, but then again,
you may very well have Novice waiting for Guru to Listen to its Question
and AT THE SAME TIME have Guru waiting for Novice to Listen to its
(possibly unsolicited) Answer.  Reversing the direction of one rendezvous
(i.e., putting the accept on the other side) will not change this.

There are tricks like time-outs and such that will prevent deadlock,
but.... one step at a time ....

---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Senior Software Engineer - AFATDS                         FAX: 219-429-5194
Hughes Defense Communications (MS 10-40)                 Home: 219-471-7206
1010 Production Road                          (Mac): wwgrol@most.fw.hac.com
Fort Wayne,  IN   46808                  (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




             reply	other threads:[~1996-11-27  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-27  0:00 W. Wesley Groleau (Wes) [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-11-25  0:00 Two-Way Task Communication In Ada (w/o Protected Objects) ericferg
1996-11-27  0:00 ` Stephen Leake
1996-11-27  0:00 ` Paul Chardon
replies disabled

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