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: a07f3367d7,66f9ac28e8d63f60 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!u16g2000pru.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Enforcing initialization protocol for protected type Date: Mon, 14 Sep 2009 14:15:16 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <1fcccc80-0142-4f07-8852-8d151ea96ee2@c37g2000yqi.googlegroups.com> <4AA92BD9.7050902@bredband.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1252962916 27703 127.0.0.1 (14 Sep 2009 21:15:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 14 Sep 2009 21:15:16 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u16g2000pru.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8323 Date: 2009-09-14T14:15:16-07:00 List-Id: On Sep 10, 9:39=A0am, Per Sandberg 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 > > ----------------------------- > =A0 =A0 =A0 =A0package p is > =A0 =A0 =A0 =A0 =A0 type Protected_t; > =A0 =A0 =A0 =A0 =A0 type initializer_t (Wrapped : not null access =A0Prot= ected_t) > =A0 =A0 =A0 =A0 =A0 =A0 is new ada.Finalization.Limited_Controlled with n= ull record; > > =A0 =A0 =A0 =A0 =A0 procedure Initialize (self : in out initializer_t); > =A0 =A0 =A0 =A0 =A0 procedure Finalize =A0 (self : in out initializer_t); > > =A0 =A0 =A0 =A0 =A0 protected type Protected_t is > =A0 =A0 =A0 =A0 =A0 =A0 =A0entry tick; > =A0 =A0 =A0 =A0 =A0 =A0 =A0procedure Initialize; > =A0 =A0 =A0 =A0 =A0 =A0 =A0procedure finalize; > =A0 =A0 =A0 =A0 =A0 private > =A0 =A0 =A0 =A0 =A0 =A0 =A0initializer : initializer_t (Protected_t'acces= s); > =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0end p; > > =A0 =A0 =A0 =A0package body p is > =A0 =A0 =A0 =A0 =A0 protected body Protected_t is > =A0 =A0 =A0 =A0 =A0 =A0 =A0entry tick when True is begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 null; > =A0 =A0 =A0 =A0 =A0 =A0 =A0end; > =A0 =A0 =A0 =A0 =A0 =A0 =A0procedure Initialize is > =A0 =A0 =A0 =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 null; > =A0 =A0 =A0 =A0 =A0 =A0 =A0end; > =A0 =A0 =A0 =A0 =A0 =A0 =A0procedure finalize is > =A0 =A0 =A0 =A0 =A0 =A0 =A0begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 null; > =A0 =A0 =A0 =A0 =A0 =A0 =A0end; > =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0 =A0 procedure Initialize (self : in out initializer_t) is > =A0 =A0 =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0self.Wrapped.Initialize; > =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0 =A0 procedure Finalize =A0 (self : in out initializer_t) = is > =A0 =A0 =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0self.Wrapped.Initialize; That last probably ought to be self.Wrapped.Finalize. > =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0end 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