comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Timeouts in Ada
Date: Wed, 23 Jul 2014 18:37:23 -0400
Date: 2014-07-23T18:37:23-04:00	[thread overview]
Message-ID: <wcciomn3dng.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 7581b098-ea30-4b34-a51e-2f0dd5a57563@googlegroups.com

Sorry for answering rather late; I don't read this newsgroup very often.

NiGHTS <nights@unku.us> writes:

> Your answer was highly intuitive, so thank you for your careful explanation. 
>
> So even if the entry call takes an hour, it will still wait the full
> hour until it completes before entering the "or delay" section? This
> is what I am understanding so far.

No (see below).

> Also, can two entry calls be placed like this?
>
>     select call_1(params)
>         ...
>     or call_2(params)
>         ...
>     or delay 10
>         ...
>     end select

No, that's illegal.  But it makes good sense, and it was proposed as a
feature of Ada 9X, but rejected.

> If so, how would it know which finishes first without having them run
> concurrently?

It doesn't matter which finishes first.  What matters is which STARTS
first.  If the above were legal, it would mean "do whichever of the 3
alternatives is ready to go first".  Hence "or" in the syntax -- we
never execute more than one alternative.

If call_1 is selected before 10 seconds elapses, then the statements
after "delay 0.0;" are not executed.

In more mechanistic terms, you need to understand the concept of an
entry being "open", which is defined in the RM.  Basically, "open" means
the entry is ready to go.  And you can think of "delay 10.0" as an entry
call that will become open after 10 seconds of elapsed time, and has an
empty body.  So it goes roughly according to this pseudo code:

    Is call_1 open?
        If so, do the entry call, and do the following "...", and we're
        all done.
        
        If not, enqueue call_1, and ask is call_2 open?

            If so, CANCEL call_1, do the call_2 entry call, and the
            following "...", and we're done.

            If not, enqueue call2.  Is "delay 10.0" open (i.e. have 10
            seconds elapsed)?

                If so, cancel the two entry calls, and do the "..." after
                the delay, and we're done.

                If not, enqueue the delay (i.e. put it on some timer
                queue).  Now we've got 3 things enqueued.  This task now
                blocks (goes to sleep).  It will be awakened by one of
                those 3 things, whichever happens first.  Whichever
                happens first will cancel the other two.  If, for
                example, call_2 becomes open first, call_1 and the delay
                are canceled, then the body of call_2 is executed, and
                then the "..." after call_2.  If call_2 takes an hour to
                run, the delay alternative is still not executed; what
                matters is whether call_2 became open (i.e. ready to
                START) within 10 seconds.

>... Don't see a point in having them run one after the
> other.

They don't.  In all cases, only one of the 3 "..." above is executed.
And only one entry body (or accept) is executed.

> I have also seen the select used with an "else". What exactly is the
> difference between "or" and "else"? Is "else" used when a "delay" is
> not involved? Otherwise I don't see the point in the "else" path.

"else" means exactly the same thing as "or delay 0.0;".

So this:

    select
        Entry_1(...);
        ...
    else
        ...
    end select;

means:

    Is Entry_1 open?
        If so, execute it, and the following "...".
        If not, execute the "..." after "else".

In other words, it means "do Entry_1 if it is open RIGHT NOW".

- Bob

  parent reply	other threads:[~2014-07-23 22:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17  5:18 Timeouts in Ada NiGHTS
2014-07-17  7:08 ` Simon Wright
2014-07-17  8:35   ` NiGHTS
2014-07-21 23:34   ` Randy Brukardt
2014-07-22  1:11     ` Shark8
2014-07-22  7:39       ` J-P. Rosen
2014-07-22  8:31         ` Simon Wright
2014-07-22 21:52       ` Randy Brukardt
2014-07-17  7:38 ` J-P. Rosen
2014-07-17  8:40   ` NiGHTS
2014-07-17 10:00     ` J-P. Rosen
2014-07-17 19:27   ` Jeffrey Carter
2014-07-17 19:51     ` J-P. Rosen
2014-07-17 20:52       ` Jeffrey Carter
2014-07-17 20:29     ` Adam Beneschan
2014-07-17 20:52       ` J-P. Rosen
2014-07-21 23:44         ` Randy Brukardt
2014-07-17 20:43     ` Jeffrey Carter
2014-07-21 23:37   ` Randy Brukardt
2014-07-17  7:42 ` Dmitry A. Kazakov
2014-07-17  8:59   ` NiGHTS
2014-07-17  9:48     ` Dmitry A. Kazakov
2014-07-17 17:10       ` NiGHTS
2014-07-17 20:45         ` Dmitry A. Kazakov
2014-07-17 16:12 ` Adam Beneschan
2014-07-17 16:46   ` NiGHTS
2014-07-17 17:11     ` Simon Wright
2014-07-17 17:58       ` NiGHTS
2014-07-17 19:02         ` Jeffrey Carter
2014-07-17 18:58       ` Jeffrey Carter
2014-07-17 18:12     ` Adam Beneschan
2014-07-17 19:27       ` Jeffrey Carter
2014-07-17 18:56     ` Jeffrey Carter
2014-07-23 22:37     ` Robert A Duff [this message]
2014-07-24  9:23       ` AdaMagica
2014-07-24 15:37         ` Robert A Duff
2014-07-25  5:16           ` Randy Brukardt
2014-07-25  9:11           ` AdaMagica
2014-07-25 16:15             ` Brad Moore
2014-07-25 16:34             ` Dmitry A. Kazakov
2014-07-17 19:27 ` Jeffrey Carter
replies disabled

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