comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Enforcing initialization protocol for protected type
Date: Mon, 14 Sep 2009 14:15:16 -0700 (PDT)
Date: 2009-09-14T14:15:16-07:00	[thread overview]
Message-ID: <b9fde919-8c26-4b75-acfc-6b2a37bca968@u16g2000pru.googlegroups.com> (raw)
In-Reply-To: 4AA92BD9.7050902@bredband.net

On Sep 10, 9:39 am, Per Sandberg <per.sandb...@bredband.net> wrote:
> The following will solve your problem but there is a catch.
> The only compiler that will fix it is to my knowledge the most bleeding
> edge gnat.
> /Per
>
> -----------------------------
>        package p is
>           type Protected_t;
>           type initializer_t (Wrapped : not null access  Protected_t)
>             is new ada.Finalization.Limited_Controlled with null record;
>
>           procedure Initialize (self : in out initializer_t);
>           procedure Finalize   (self : in out initializer_t);
>
>           protected type Protected_t is
>              entry tick;
>              procedure Initialize;
>              procedure finalize;
>           private
>              initializer : initializer_t (Protected_t'access);
>           end;
>        end p;
>
>        package body p is
>           protected body Protected_t is
>              entry tick when True is begin
>                 null;
>              end;
>              procedure Initialize is
>              begin
>                 null;
>              end;
>              procedure finalize is
>              begin
>                 null;
>              end;
>           end;
>           procedure Initialize (self : in out initializer_t) is
>           begin
>              self.Wrapped.Initialize;
>           end;
>           procedure Finalize   (self : in out initializer_t) is
>           begin
>              self.Wrapped.Initialize;

That last probably ought to be self.Wrapped.Finalize.

>           end;
>        end p;

By the way, I think this will work, but it does mean that a protected
action will be called on a protected object before the object is fully
initialized.  I've looked through the language rules and I'm not
convinced this is a problem.  In Ada 95, 3.3.1(18-19) appeared to mean
that the object was *created* before its components were initialized,
and I suspect that creating the protected object included creating its
entry queues and completing whatever else would be necessary so that
the protected action that takes place when the Initialize protected
subprogram was called could be completed successfully (including
servicing the entry queues as required by 9.5.1(7)).  In Ada 2005,
however, 3.3.1(18-19) have been merged into one paragraph, so that the
timing isn't quite as clear, depending on how you interpret the new
paragraph.  Any language lawyers care to comment?  Is Per's example
(with additional code as needed in the Initialize procedure)
guaranteed to work (as long as the Initialize protected procedure
doesn't reference any components with per-object constraints that
haven't yet been initialized), or is it ambiguous whether it will work
or not?

                                        -- Adam




  reply	other threads:[~2009-09-14 21:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-07 15:15 Enforcing initialization protocol for protected type Maciej Sobczak
2009-09-07 17:01 ` Georg Bauhaus
2009-09-07 20:19   ` Maciej Sobczak
2009-09-10 17:07     ` Georg Bauhaus
2009-09-11  5:01     ` AdaMagica
2009-09-11  9:03       ` Dmitry A. Kazakov
2009-09-11 15:25         ` AdaMagica
2009-09-11 16:27           ` Dmitry A. Kazakov
2009-09-11 22:24             ` Randy Brukardt
2009-09-12  8:44               ` Dmitry A. Kazakov
2009-09-10 16:39 ` Per Sandberg
2009-09-14 21:15   ` Adam Beneschan [this message]
2009-09-15  0:27     ` Randy Brukardt
replies disabled

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