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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8fa8eec8401ec58 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Post hoc making a type thread safe Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <6b7vr9F3b6cjlU1@mid.individual.net> Date: Tue, 10 Jun 2008 21:42:51 +0200 Message-ID: <1o2e8krc3q5l6$.1sivotu6yqxwa$.dlg@40tude.net> NNTP-Posting-Date: 10 Jun 2008 21:42:51 CEST NNTP-Posting-Host: 233d24aa.newsspool1.arcor-online.net X-Trace: DXC=2;me?FC1M^c9kIfcjg:0fdic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbWOemhf?UNZn[6LHn;2LCVnCOgUkn_?_YoH?5Xl\M1I?fI71e7eog\5b X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:638 Date: 2008-06-10T21:42:51+02:00 List-Id: On Tue, 10 Jun 2008 20:36:27 +0200, Alex R. Mosteo wrote: > I have a rather large object (in terms of # of subprograms) which is standard > tagged record. I want to use it in a thread safe manner, and I wonder if > there's some better solution than proxying everything with a protected type. > I'm not sure if some new 2005 feature can help in this regard. > > Any gain would be nice; for example, is there some way of using renames to > provide the bodies of the protected object using the original object ones? I > can't think of a way so I ask in case I'm missing something... Also, I have > access to both public, private and body of the original type, in case this is > of use. > > In practice I'm looking for something equivalent to: > > -- Not Ada > -- protected type Safe is new Unsafe with null record; I doubt that interfaces would help you in that. Unsafe is a concrete type. It is just too late. For a protected object it is always too late because they are "final." BTW, it would be not that useful, if it were Ada. (Not denying that it should be Ada.) The reason is that some inherited operations could be blocking or lengthy. They would be poor candidates for making them protected. More useful could be multiple inheritance from a task type converting primitive operations to entries (i.e. making a monitor out of Unsafe). Even better would be some support for delegation. Anyway, the pattern I am using for this purpose is admittedly clumsy: type Safe is new Unsafe with private; overriding procedure Each_And_Every (X : Safe); ... private protected type Lock is procedure Each_And_Every_Wrapper (X : Unsafe); ... end Lock; type Safe is new Unsafe with record Sequencer : Lock; -- This can be a shared object too end record; ------------------------------- protected body Lock is procedure Each_And_Every_Wrapper (X : Unsafe) is begin Each_And_Every (X); end; ... end Lock; procedure Each_And_Every (X : Safe) is begin X.Sequencer.Each_And_Every_Wrapper (Unsafe (X)); end Each_And_Every; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de