comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Advice, tasking and hardware
Date: Thu, 26 May 2016 13:35:45 -0700
Date: 2016-05-26T13:35:45-07:00	[thread overview]
Message-ID: <ni7mg6$c7u$1@dont-email.me> (raw)
In-Reply-To: <d7312808-f2e0-466c-8db5-db5bdb43e811@googlegroups.com>

On 05/26/2016 09:41 AM, patrick@spellingbeewinnars.org wrote:
> 
> I could write a mostly single threaded application that used tasking for
> error detection/handling only.
> 
> I could queue tasks. One would be called just before calling into a driver.
> The task would delay for a given amount of time and if the call to the driver
> blocked unexpectedly the task would reach a point were it will notify the
> user with a detailed error message. If the driver call did not block another
> task would be called to signal that the driver call completed on time and the
> first task would be notified at rendezvous that it was on time and the tasks
> would queue again and wait for the next driver call.

It sounds like you're interested in a "watchdog", which does something if an
action doesn't complete in time. Possible ways to implement this include the
selective abort (ATC), a timing event, or using a task.

ATC is simple:

select
   delay until Deadline;

   -- Whatever reporting or corrective action is needed
then abort
   Perform_Action;
   -- Whatever success reporting is needed
end select;

If the delay expires, an attempt is made to abort the "then abort" part.
Obviously you wouldn't use it if you don't want to abort the call. Note also
that there are things that cannot be aborted, so this may not work if
Perform_Action contains any of them. You should review ARM 9.8 to see if they
apply to you.

http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-9-8.html

A timing event (ARM D.15) has an associated handler, which is a protected
procedure. Depending on what your compiler will let you get away with in a
protected operation, and how concerned you are about portability, you may be
able to put your reporting/recovery in the handler, and this is almost as simple
as ATC, though it's a bit harder to find out what the recovery options are. If
you want to do any potentially blocking operations, to be portable, your handler
needs to simply open the barrier on an entry of the same PO, and a task that
waits on that entry does the actual recovery. If you're going to do that, it's
simpler and clearer to just use a task.

You'd use a timing event this way

Event.Set_Handler (At_Time => Deadline, Handler => PO.Handler'access);
Perform_Action;
Event.Cancel_Handler (Cancelled => Canceled);

Deadline needs to have enough slack in it to prevent a race condition between
the handler being invoked and Cancel_Handler being called.

A task would look like

task Watchdog is
   entry Start (Deadline : in Time);
   entry Stop;
end Watchdog;

and is used similarly to a timing event

Watchdog.Start (Deadline => Deadline);
Perform_Action;
Watchdog.Stop;

and has a similar comment about race conditions.

The body of Watchdog is like

Forever : loop
   select
      accept Start (Deadline : in Time) do
         Expiry := Deadline;
      end Start;
   or
      terminate;
   end select;

   select
      accept Stop;
   or
      delay until Expiry;

      -- Recovery
   end select;
end loop Forever;

Note that this could be generic on the recovery action.

-- 
Jeff Carter
"This trial is a travesty. It's a travesty of a mockery of a
sham of a mockery of a travesty of two mockeries of a sham. ...
Do you realize there's not a single homosexual on that jury?"
Bananas
27

  parent reply	other threads:[~2016-05-26 20:35 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-25 21:24 Advice, tasking and hardware patrick
2016-05-26  1:09 ` Jeffrey R. Carter
2016-05-26  8:13   ` Simon Wright
2016-05-26  7:26 ` Dmitry A. Kazakov
2016-05-26 16:41   ` patrick
2016-05-26 17:56     ` Dmitry A. Kazakov
2016-05-26 20:35     ` Jeffrey R. Carter [this message]
2016-05-26 19:35   ` Jeffrey R. Carter
2016-05-26 20:51     ` patrick
2016-05-27  7:50     ` Dmitry A. Kazakov
2016-05-27 18:00       ` Simon Wright
2016-05-27 19:06       ` Jeffrey R. Carter
2016-05-27 22:05         ` Randy Brukardt
2016-05-27 23:09           ` Jeffrey R. Carter
2016-05-27 19:13       ` Shark8
2016-05-27 20:27         ` Dmitry A. Kazakov
2016-05-27 22:27           ` Randy Brukardt
2016-05-28  6:49             ` Dmitry A. Kazakov
2016-05-28 14:38           ` Shark8
2016-05-28 15:45             ` Dmitry A. Kazakov
2016-05-28  0:25 ` rieachus
2016-05-28  1:57   ` patrick
2016-05-28  4:13   ` Jeffrey R. Carter
2016-06-01 14:37     ` rieachus
2016-06-01 19:09       ` Dmitry A. Kazakov
2016-06-06  3:33         ` rieachus
2016-06-06  7:18           ` Dmitry A. Kazakov
2016-06-07 16:53             ` rieachus
2016-06-07 20:21               ` Dmitry A. Kazakov
2016-06-08  4:06                 ` rieachus
2016-06-08  7:29                   ` Dmitry A. Kazakov
2016-06-08 12:56                     ` rieachus
2016-06-08  0:19               ` Dennis Lee Bieber
replies disabled

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