comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Example question
Date: Sun, 26 Oct 2014 16:33:11 +0200
Date: 2014-10-26T16:33:11+02:00	[thread overview]
Message-ID: <cb4f18FoggpU1@mid.individual.net> (raw)
In-Reply-To: <0fbd755d-7bcf-42b1-a20b-c6a2c74c7d6e@googlegroups.com>

On 14-10-26 15:27 , compguy45@gmail.com wrote:
> body Spreadsheet_Task is
>     begin
>         loop
>             select
>                 accept Recalculate;
>                 Do_Recalculation;
>             or
>                 accept Shutdown;
>                 exit;
>             end select;
>         end loop;
>     end Spreadsheet_Task;
> 
> Tutorial says "If calls to both entries are already pending, one
> will be accepted non-deterministically." what does that mean?

One of the two entry calls will be accepted, the corresponding accept
statement will be executed, and there is no telling which entry will be
accepted. It might be Recalculate, it might be Shutdown.

> If calls are pending on bith entries it might happend that
> Shutdown is accepted and exits

Yes.

> in which case thats not good solution at all

Solution to what? You have not told us what is the problem to be solved.

For some applications, it makes sense to continue "calculating" as long
as there are requests, and let the Shutdown be delayed. For other
applications, the opposite approach is desired, and Shutdown should take
precedence.

The accept statement is neutral and does not favour one of its
alternatives over the others. However, you can use guards on the accept
alternatives to enforce some ordering.

For example, if you want to be sure of accepting and executing a
Shutdown even if there are also pending Recalculate requests, you can
guard the Recalculate alternative with the Count attribute of the
Shutdown entry:

      loop
          select
              when Shutdown'Count = 0 =>
                 accept Recalculate;
                 Do_Recalculation;
          or
              accept Shutdown;
              exit;
          end select;
      end loop;

Then, if there is a Shutdown call waiting when the select is executed,
the Recalculate alternative is closed, and the Shutdown call is certain
to be accepted.

If there are no pending Shutdown calls when the select is executed, both
alternatives are open, and the first call is accepted. If calls to
Recalculate and Shutdown are made simultaneously, one of the calls is
accepted, but we cannot know which one will be accepted. However, if it
happens to be the Recalculate call, on the next iteration of the loop
Shutdown'Count will be positive, the Recalculate alternative will be
closed, and the Shutdown call will be accepted.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
      .      @       .


      parent reply	other threads:[~2014-10-26 14:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-26 13:27 Example question compguy45
2014-10-26 14:18 ` Martyn Pike
2014-10-26 15:46   ` J-P. Rosen
2014-10-26 16:53     ` Martyn Pike
2014-10-26 14:21 ` Shark8
2014-10-26 15:42   ` Simon Wright
2014-10-26 15:48   ` Robert A Duff
2014-10-26 14:33 ` Niklas Holsti [this message]
replies disabled

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