From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.140.104.51 with SMTP id z48mr11753199qge.27.1464395160227; Fri, 27 May 2016 17:26:00 -0700 (PDT) X-Received: by 10.157.40.228 with SMTP id s91mr259251ota.13.1464395160184; Fri, 27 May 2016 17:26:00 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!j92no27988qga.1!news-out.google.com!yi6ni921igc.0!nntp.google.com!q6no2065903igz.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 27 May 2016 17:25:59 -0700 (PDT) In-Reply-To: <25c43463-47ca-4021-82ee-299e6a075faa@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8202:8510:5985:2c17:9409:aa9c; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8202:8510:5985:2c17:9409:aa9c References: <25c43463-47ca-4021-82ee-299e6a075faa@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2c0dfaf8-9344-4b9c-87b4-12de687687ce@googlegroups.com> Subject: Re: Advice, tasking and hardware From: rieachus@comcast.net Injection-Date: Sat, 28 May 2016 00:26:00 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:30499 Date: 2016-05-27T17:25:59-07:00 List-Id: I think there is a lot of well argued stuff here which is several months ah= ead 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 en= vironment/solution space, a small (in text terms) change in the requirement= s 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 yo= u need to deal with state in the instrument. Otherwise use a protected obj= ect to insure sequential communications. Some instruments have state, lots of state, others are nice and use a state= less protocol. To use POs, to control other hardware you definitely want t= o do a classic semaphore. Any thread/task talking to that device does a Se= ize, 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 clea= n, but your task may end up pages long to deal with error states and recove= ry. Finally how you deal with task termination will depend to a great deal on t= he safety requirements. There is a design pattern when you need each activ= e 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 wa= nt to call abort in Ada. You have a task which deals with normal operation= s, and a emergency task which turns of the gas, high voltage, fuel, or what= ever.) task Killer is end Killer -- no entries. task body Killer is=20 begin Shutdown.Suspend.Wait; select Local_Task.Shutdown; or delay XXX; --- delay time will depend on physical system propertie= s. 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;=20