comp.lang.ada
 help / color / mirror / Atom feed
From: rieachus@comcast.net
Subject: Re: Advice,  tasking and hardware
Date: Fri, 27 May 2016 17:25:59 -0700 (PDT)
Date: 2016-05-27T17:25:59-07:00	[thread overview]
Message-ID: <2c0dfaf8-9344-4b9c-87b4-12de687687ce@googlegroups.com> (raw)
In-Reply-To: <25c43463-47ca-4021-82ee-299e6a075faa@googlegroups.com>

I think there is a lot of well argued stuff here which is several months ahead of where the OP is.

If you are writing a controller for a wall of instruments talking IEEE 488 or some such, and the goal is to write programs for automated testing, the first huge win with Ada is:

   In Ada you model the environment, not the problem set.

It is not unusual to have changes in the requirements for automated testing (or just about any other field) at the last minute.  If you modeled the environment/solution space, a small (in text terms) change in the requirements with require only a small change in the code.

Next, there are choices you have to make in doing your modelling.  Having a package corresponding to each instrument, and putting a task inside iff you need to deal with state in the instrument.  Otherwise use a protected object to insure sequential communications.

Some instruments have state, lots of state, others are nice and use a stateless protocol.  To use POs, to control other hardware you definitely want to do a classic semaphore.  Any thread/task talking to that device does a Seize, and a Release when done.  For devices with state, you need a task that tracks the state of the device.  Would it were so simple as that makes it sound.  The interface the package presents to the rest of the world is clean, but your task may end up pages long to deal with error states and recovery.

Finally how you deal with task termination will depend to a great deal on the safety requirements.  There is a design pattern when you need each active device to have a call during shutdown and multiple shutdowns are the way to go.  Basically you have a shutdown package in the with list of packages with hidden tasks.  You create a new task which does what is necessary and it waits on a task entry provided by the shutdown package:

package Shutdown is
  task Suspend is
    entry Stop;
    entry Wait;
  end Suspend;
end Shutdown;
...
package body Shutdown is
begin
 task body Suspend is
 begin
   accept Stop;
   loop
     select
       accept Wait;
     or
       accept Stop; -- in case of multiple calls to Stop.
     or
       terminate;
     end select;
   end loop;
 end Shutdown;

  Now any package can call Shutdown.Suspend.Wait from a task that does the necessary shutdown actions.  (This is about the only situation where you want to call abort in Ada.  You have a task which deals with normal operations, and a emergency task which turns of the gas, high voltage, fuel, or whatever.)

   task Killer is
   end Killer  -- no entries.

   task body Killer is 
   begin
     Shutdown.Suspend.Wait;
     select
       Local_Task.Shutdown;
     or delay XXX;  --- delay time will depend on physical system properties.
     end select;
     delay YYY;   --- delay time will depend on physical system properties.
     abort Local_Task;
     -- shut down everything controlled by Local_Task here.
   end Killer; 

  parent reply	other threads:[~2016-05-28  0:25 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
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 [this message]
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