comp.lang.ada
 help / color / mirror / Atom feed
* Re: conditional entry call ?
@ 1992-09-23 17:49 Bob Kitzberger
  0 siblings, 0 replies; 2+ messages in thread
From: Bob Kitzberger @ 1992-09-23 17:49 UTC (permalink / raw)


shengru@cs.uno.edu (Shengru Tu) writes:

>I know that a typical conditional entry call can be:
>	...
>	select
>		TASK_NAME.ENTRY_NAME;
>		...
>	or
>		delay 10.0;
>	end select;

Actually that's a timed entry call [ARM 9.7.3].  A conditional entry call 
[ARM 9.7.2] is:

	select
	  entry_call_statement
	  [sequence_of_statements]
	else
	  sequence_of_statements
	end select;


>But is the following code legal, where I put another entry call stmt in
>the position of "stmt":
>	  ...
>          select
>                T2.E2;
>          or
>                T3.E3;
>          end select;
>	  ...

No, it's illegal (see ARM 9.7.3: the second alternative must be a delay
alternative).  You may be thinking of:

	select
	  T2.E2;
	else
	  T3.E3;
	end select;

In which case, by ARM 9.7.2,  the first alternative's entry call will be
cancelled if not immediately possible, and the 'else' alternative will be
followed.  This can be any sequence of statements, but since it's an
entry call it will behave as a stand-alone entry call, and waits for 
rendezvous with T3.E3.  If, while blocked on the T3.E3 entry call, task T2
hits the accept for E2, it's tough cookies since the select alternative has
already been evaluated.

It may be that what you are asking for in a multi-way entry call (the
counterpart to a selective wait).  As far as I know, it can't be done in 
Ada 83.  Does anybody have a multi-way entry call solution?

	.Bob.



with text_io;
use  text_io;
procedure test is

  task t is 
    entry a;
    entry b;
  end t;

  task body t is
  begin
    accept a do
      put_line( "a");
    end a;

    accept b do
      put_line( "b");
    end b;

    delay 1.0;		-- make sure first select alternative is evaulated

    accept a do
      put_line( "a");
    end a;
  end t;


begin

  select
    t.a;		-- immediately succeeds
  else
    t.b;
  end select;

  select
    t.a;		-- not possible, call t.b
  else
    t.b;		-- succeeds
  end select;

  select
    t.a;		-- not possible, call t.b
  else
    t.b;
    -- stuck calling b here
  end select;

end test;

----------------
Bob Kitzberger          VisiCom Laboratories, Inc.
rlk@visicom.com         10052 Mesa Ridge Court, San Diego CA 92121 USA
                        +1 619 457 2111    FAX +1 619 457 0888

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

* Re: conditional entry call ?
@ 1992-09-23 21:08 Dave Marshall
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Marshall @ 1992-09-23 21:08 UTC (permalink / raw)


In article <1992Sep22.232926.25966@cs.uno.edu>, shengru@cs.uno.edu (Shengru Tu)
 writes:
> But is the following code legal, where I put another entry call stmt in
> the position of "stmt":
> 	  ...
>           select
>                 T2.E2;
>           or
>                 T3.E3;
>           end select;
> 	  ...
>
That code is not legal.  I humbly offer the following substitute construct:

LRM 9.7.2 presents an example procedure SPIN to demonstrate select-else.
One could similarly do the following (although it's bogus, IMHO):

loop
   select
      T2.E2;
      exit;
   else
      select
         T3.E3;
         exit;
      else
         null;
      end select;
   end select;
end loop;

The moral:  If you find yourself compelled to implement a select-or construct,
maybe you should reevaluate the way you're doing things.  The code I have
presented is garbage, and it should be used only if absolutely necessary.
-- 
                                           Dave Marshall
                                           dmarshal@stars.reston.unisys.com

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

end of thread, other threads:[~1992-09-23 21:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-09-23 21:08 conditional entry call ? Dave Marshall
  -- strict thread matches above, loose matches on Subject: below --
1992-09-23 17:49 Bob Kitzberger

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