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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4e5770c49b971630 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.weisnix.org!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Wed, 04 May 2011 16:46:21 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: High-Integrity OO and controlled types References: <679e3217-98dd-43c1-86f6-2038a029c3ea@b19g2000yqg.googlegroups.com> <94f3a272-d071-4a74-bfbd-8f2b4c2347cf@m10g2000yqd.googlegroups.com> <4dbfe6cc$0$7664$9b4e6d93@newsspool1.arcor-online.net> <1in9ypl17vu1t$.1shivr91x8zw6.dlg@40tude.net> <4dc01dca$0$6885$9b4e6d93@newsspool2.arcor-online.net> <1ds39akl3dbii$.mlyj7piip5o3.dlg@40tude.net> <4dc112cf$0$6772$9b4e6d93@newsspool3.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4dc166bd$0$6973$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 04 May 2011 16:46:21 CEST NNTP-Posting-Host: 4b137c36.newsspool4.arcor-online.net X-Trace: DXC=S[XFfD4K0mB@k=MdN::NBI4IUKJLh>_cHTX3jM\k>Aj7Ln2QA X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:20124 Date: 2011-05-04T16:46:21+02:00 List-Id: On 04.05.11 11:28, Dmitry A. Kazakov wrote: > This does not read as a complete description. In what sense are the parts > of the array shared? If sharing means only independent use of the parts, > then what sense has the array as an object in this design? Independently > used parts must be local to their users. Now, if there is something else > behind this, i.e. that parts are sometimes used independently and sometimes > together, then too little is said about the mechanisms used for the latter, > and most intricate part of design. > >> This sounds like one could design types that >> do(!) just this as part of their finalization. But it does >> seem like an awful lot of overhead, and is essentially >> a type that is-a procedure. > > You see that as an overhead only because the picture is incomplete. Once > you fill the gaps, you will see how "exit action" firs there. That would > definitely involve additional objects, e.g. controlled "handles" of which > finalization would deal with "exit" and other operations would serve > interlocking etc. A simple example (full source linked, but may not be necessary); the intention is for it to be fairly low level data manipulation. It is not nice, and could be generalized in several ways, I think. If there is justification for doing so. Array `Central` is manipulated by two tasks A and B. When these have finished filling `Central`, the env task computes the final result by counting certain values in `Central`. Communication uses simple variables and visibility. The task B is sensitive to a special piece of input and will restart its work from the beginning when the input testing function raises Junk_Signal. I imagine it is possible to redesign, yet I'd like to know the ROI; the program is almost a Ravenscar program. There are no pointers. with Printing; procedure Shared is -- ---------------------------------------------------------------- -- Outline: -- -- Two tasks will work on a shared array, each task taking care of -- its share of slots. After they have finished, all slots will -- have valid values, some of which are interesting. Count -- these. -- ---------------------------------------------------------------- package Stuff is -- -- Items that will be stored in the array. Each component -- will be of type ID_Code. No value means = No_Code. -- type Digit_Position is range 1 .. 4; type Code_Digit is ('U', 'V', 'W', 'X', 'Y', 'Z'); type ID_Code is array (Digit_Position) of Code_Digit; No_Code : constant ID_Code; function Image (Id : Id_Code) return String; type Slot_Index is range 1 .. 1023; type Work_Item is array (Slot_Index) of ID_Code; -- type of the shared array function Is_Filled (W : Work_Item) return Boolean; procedure Init (W : in out Work_Item); function Interesting_Result (W : Work_Item) return Natural; -- number of interesting ID_Code values in `W` (likely `Central`) private No_Code : constant ID_Code := ID_Code'('X', 'X', 'X', 'X'); end Stuff; package body Stuff is separate; use Stuff; Central : Work_Item; Result : Natural := Natural(Slot_Index'Last) + 1; -- also used as flag. Set `Result := 0` when the tasks may start -- doing their work pragma Atomic(Result); package Slaves is -- Each task will work with its share of slots in `Central`. -- A and B try hard to find good ID_Code values from some -- external source, B tries especially hard. task A; task B; end Slaves; package body Slaves is separate; begin Init (Central); pragma Assert (not Is_Filled (Central)); Result := 0; -- now poll until A and B have filled Central loop exit when Is_Filled (Central); delay 0.2; end loop; Result := Interesting_Result(Central); Printing.Output.Write (Natural'Image(Result) & " interesting items", NL => True); end Shared; Rest is here: http://home.arcor.de/bauhaus/Ada/shrd.ada