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=ham 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!feeder.news-service.com!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Post hoc making a type thread safe Date: Wed, 11 Jun 2008 13:35:19 +0200 Message-ID: <6b9rhhF397rp0U1@mid.individual.net> References: <6b7vr9F3b6cjlU1@mid.individual.net> <1o2e8krc3q5l6$.1sivotu6yqxwa$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net HLUFNdcPjFO2pfUVLceM3QPF1cMrP4kEKjiukmqnscrJb4Mfo= Cancel-Lock: sha1:EEPpapzn3aXA6/OW+8Ygjq9I/gs= User-Agent: KNode/0.10.9 Xref: g2news1.google.com comp.lang.ada:641 Date: 2008-06-11T13:35:19+02:00 List-Id: Dmitry A. Kazakov wrote: > 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 Yep, I realized there would be problems with such an approach. > 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: Thanks, this is basically what I was planning to do. I was hoping for some reduction in typing, but I guess there's no way around. > 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; >