comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: embed accept statement in procedures not possible?
Date: 9 May 2007 07:56:45 -0700
Date: 2007-05-09T07:56:45-07:00	[thread overview]
Message-ID: <1178722605.068961.76180@n59g2000hsh.googlegroups.com> (raw)
In-Reply-To: <u9sr1f.tue.ln@hunter.axlog.fr>

On May 9, 12:12 am, Jean-Pierre Rosen <r...@adalog.fr> wrote:
> Adam Beneschan a écrit :> Actually, though, why is a syntactic rule necessary (as opposed to a
> > run-time check)?
>
> 1) In general, Ada enforces static checking rather than dynamic
> checking, especially when (like here) the problem is really structural
>
> 2) There would be a distributed cost. Any accept statement would need to
> access, at least Current_Task, and (believe it or not) this can be
> costly in some environments.

I don't think #2 is true.  Any ACCEPT statement that is currently
legal would not have to perform this check, and the compiler would of
course be able to tell statically whether the check would need to be
done or not, since that would be just the same check it's performing
now to enforce the rule.  (And I think there would be cases where a
compiler can tell that no check is needed even for an ACCEPT inside a
procedure.  Off the top of my head, I think this is the case if the
task has no nested task types, 'Access is never used on the procedure,
and the procedure is never used as a generic actual parameter.)

If I'm right and there's no distributed cost, then #1 doesn't provide
enough of a reason to disallow such ACCEPTs.  There may be other
reasons I haven't thought of that would make this a bad idea (perhaps
some implementations need the task body to be the top routine on the
task's stack when a rendezvous takes place?) or just not worth the
effort.  In any case, though, I still think your earlier statement,
that the rule is "necessary" to make sure that a task can accept only
its own entries, is incorrect.

And although Stephen gave an example of how some problems can be
solved by putting a shared procedure inside an ACCEPT, his example was
a fairly simple one that can't always be generalized.  Suppose you
would really like a procedure that does an ACCEPT somewhere inside a
loop; you can't just yank the ACCEPT out of the loop and put it in the
main task body without some significant reorganization of the logic.

I don't use tasks much at all, so I can't come up with a real-world
example where this restriction is an annoyance or a problem, other
than the original poster's situation.

                                      -- Adam




  reply	other threads:[~2007-05-09 14:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-04 15:04 embed accept statement in procedures not possible? Gerd
2007-05-04 16:58 ` Jean-Pierre Rosen
2007-05-04 19:45   ` Adam Beneschan
2007-05-09  7:12     ` Jean-Pierre Rosen
2007-05-09 14:56       ` Adam Beneschan [this message]
2007-05-10 11:43         ` Jean-Pierre Rosen
2007-05-10 17:26           ` Pascal Obry
2007-05-04 17:03 ` (see below)
2007-05-04 21:22   ` adaworks
2007-05-05 23:54 ` Stephen Leake
replies disabled

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