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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fd189a20f95495f3 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!z39g2000yqz.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Task components, the rationale Date: Wed, 13 Jul 2011 13:58:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 83.3.40.82 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1310590717 7656 127.0.0.1 (13 Jul 2011 20:58:37 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 13 Jul 2011 20:58:37 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z39g2000yqz.googlegroups.com; posting-host=83.3.40.82; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:21169 Date: 2011-07-13T13:58:36-07:00 List-Id: On Jul 13, 8:52=A0pm, "Dmitry A. Kazakov" wrote: > Now, if My_Worker started before completion of Initialize then this body > > =A0 =A0task body Worker is > =A0 =A0begin > =A0 =A0 =A0 =A0Self.Foo; -- Boom! > > could call Foo of T or any of its derived type *before* Initialize, i.e. > before the object's construction is done! That would be a much worse > problem. I don't even think you need to introduce tasks to show the problem - what if the component is of another controlled type? Then you have two nested calls to distinct Initialize operations - the first one for the component (where you have the discriminant access value to play with) and the second one for the whole, which is too late: with Ada.Finalization; with Ada.Text_IO; procedure Test is type Outer; type Inner (Shell : access Outer) is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (Self : in out Inner); type Outer is new Ada.Finalization.Limited_Controlled with record I : Inner (Outer'Access); Some_Value : Integer; end record; overriding procedure Initialize (Self : in out Outer); procedure Initialize (Self : in out Inner) is begin Ada.Text_IO.Put_Line ("initializing inner, Self.Shell.Some_Value =3D" & Integer'Image (Self.Shell.all.Some_Value)); end Initialize; procedure Initialize (Self : in out Outer) is begin Self.Some_Value :=3D 123; Ada.Text_IO.Put_Line ("initialized outer, Some_Value =3D" & Integer'Image (Self.Some_Value)); end Initialize; X : Outer; begin null; end Test; $ gnatmake test ... $ ./test initializing inner, Self.Shell.Some_Value =3D 0 initialized outer, Some_Value =3D 123 $ We are messing with the state that does not yet exist. Oops. > There is no simple solution for this. You have to just, you know, simply, introduce constructors to the language. This is my pet feature for Ada 2020. :-) > To start with tasks must be > inheritable from and their bodies must be primitive or class-wide > operations, because aggregation (composition) + Rosen's trick is > necessarily broken. It's not about tasks, it's about access discriminants to outer records - they introduce circular references (outer has inner, inner knows outer) and as such are evil. -- Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com