From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1142654921f4156d X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: Re: Two-Way Task Communication In Ada (w/o Protected Objects) Date: 1996/11/27 Message-ID: <9611271353.AA03732@most>#1/1 X-Deja-AN: 201044404 sender: Ada programming language comments: Gated by NETNEWS@AUVM.AMERICAN.EDU mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-11-27T00:00:00+00:00 List-Id: 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 ---------------------------------------------------------------------------