comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex R. Mosteo" <devnull@mailinator.com>
Subject: Re: Post hoc making a type thread safe
Date: Wed, 11 Jun 2008 13:35:19 +0200
Date: 2008-06-11T13:35:19+02:00	[thread overview]
Message-ID: <6b9rhhF397rp0U1@mid.individual.net> (raw)
In-Reply-To: 1o2e8krc3q5l6$.1sivotu6yqxwa$.dlg@40tude.net

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;
> 




  reply	other threads:[~2008-06-11 11:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-10 18:36 Post hoc making a type thread safe Alex R. Mosteo
2008-06-10 19:42 ` Dmitry A. Kazakov
2008-06-11 11:35   ` Alex R. Mosteo [this message]
2008-06-11  0:35 ` tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox