From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: another way to shoot yourself in the foot?
Date: Tue, 24 Jun 2008 19:52:41 +0200
Date: 2008-06-24T19:52:41+02:00 [thread overview]
Message-ID: <1s88o46xl9o9b$.1e88zxl9es93z$.dlg@40tude.net> (raw)
In-Reply-To: wccd4m6sqa1.fsf@shell01.TheWorld.com
On Tue, 24 Jun 2008 13:20:54 -0400, Robert A Duff wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> On Tue, 24 Jun 2008 07:59:35 -0700 (PDT), Adam Beneschan wrote:
>>
>>> I've probably lost the plot of this thread. But in regards to the
>>> example, I think the example is "no". The semantics should be exactly
>>> the same as if Interesting's body were simply "return X : T;". The
>>> first extended return statement that raises an exception doesn't have
>>> any effect, in terms of starting a new task or anything like that,
>>> because the RM explicitly says that task activation doesn't occur
>>> until after the function returns (6.5(7)).
>>
>> OK, then the notorious problem of Ada 95, that a task cannot be
>> initialized, in the sense that upon initialization you could pass
>> parameters to it via a rendezvous, is still there.
>
> The way to initialize tasks in Ada 95 and Ada 2005 is to pass
> discriminants to the task.
It is a very limited way, and in any case semantically it is different from
initialization parameters. A parameter is not required to outlive
initialization, while a discriminant is. Logically discriminant is a
constraint, it is by no way a parameter.
>> Tasks finalization does not work either, because there is no destructing
>> functions ("malfunctions" to use the name Robert Duff suggested (:-))
>> anyway.
>
> I'm not sure what the issue is, here. Masters wait for their dependent
> tasks to terminate (or be "ready" to terminate -- at a terminate
> alternative) BEFORE the task objects are finalized. So when a task
> object is finalized, it is already terminated, so it doesn't make sense
> to rendezvous with it.
Nope, it makes a lot of sense, but it just does not work. Because a task
rarely knows if it should complete. The enclosing object does not expect
its components to prematurely finalize themselves. It is just a bad design
turned upside down:
task type Foo is
Start_Up (...);
Shut_Down (...);
end Foo;
type T is new Ada.Finalization.Limited_Controlled with record
X : Foo; -- No chance to make this working
...
There is no other option than to use access to task instead:
type Foo_Ptr is access Foo;
type T is new Ada.Finalization.Limited_Controlled with record
X : Foo_Ptr; -- This is OK, but more C++ than Ada!
...
procedure Initialize (Obj : in out T) is
procedure Free is new Ada.Unchecked_Deallocation (Foo, Foo_Ptr);
begin
Obj.X := new Foo;
Obj.X.Start_Up (...);
exception
when others => -- We don't want it leaking, right?
Free (Obj.X); -- Probably this will hang, nevertheless...
raise;
end Initialize;
procedure Finalize (Obj : in out T) is
procedure Free is new Ada.Unchecked_Deallocation (Foo, Foo_Ptr);
begin
Obj.X.Shut_Down (...);
Free (Obj.X);
exception
when others =>
Free (Obj.X);
raise;
end Finalize;
A quite intrusive pattern, isn't it?
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-06-24 17:52 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-20 9:03 another way to shoot yourself in the foot? fedya_fedyakoff
2008-06-20 9:34 ` Dmitry A. Kazakov
2008-06-20 9:48 ` fedya_fedyakoff
2008-06-20 10:01 ` Ludovic Brenta
2008-06-20 10:05 ` christoph.grein
2008-06-20 10:26 ` Dmitry A. Kazakov
2008-06-20 16:12 ` Adam Beneschan
2008-06-20 15:48 ` Adam Beneschan
2008-06-20 19:27 ` Robert A Duff
2008-06-20 23:37 ` Jeffrey R. Carter
2008-06-21 8:56 ` Dmitry A. Kazakov
2008-06-22 20:44 ` Robert A Duff
2008-06-23 7:49 ` Dmitry A. Kazakov
2008-06-24 4:02 ` george.priv
2008-06-24 7:30 ` Dmitry A. Kazakov
2008-06-24 17:16 ` Robert A Duff
2008-06-24 19:15 ` Jeffrey R. Carter
2008-06-24 20:31 ` Robert A Duff
2008-06-24 20:50 ` Ludovic Brenta
2008-06-24 23:02 ` Robert A Duff
2008-06-24 23:42 ` Georg Bauhaus
2008-06-24 21:24 ` Jeffrey R. Carter
2008-06-24 23:24 ` Robert A Duff
2008-06-25 15:07 ` Adam Beneschan
2008-06-24 14:59 ` Adam Beneschan
2008-06-24 16:41 ` Dmitry A. Kazakov
2008-06-24 17:20 ` Robert A Duff
2008-06-24 17:52 ` Dmitry A. Kazakov [this message]
2008-06-24 23:35 ` Georg Bauhaus
2008-06-25 8:09 ` Dmitry A. Kazakov
2008-06-25 10:32 ` Georg Bauhaus
2008-06-25 12:06 ` Dmitry A. Kazakov
2008-06-22 20:37 ` Robert A Duff
2008-06-22 21:25 ` Jeffrey R. Carter
2008-07-04 20:52 ` Colin Paul Gloster
2008-07-04 22:15 ` (see below)
2008-07-05 16:06 ` Colin Paul Gloster
2008-07-05 13:38 ` Gary Scott
2008-07-05 16:42 ` Colin Paul Gloster
2008-07-05 19:00 ` Gary Scott
2008-07-09 19:39 ` Colin Paul Gloster
2008-07-09 20:35 ` Richard Maine
2008-07-09 22:49 ` Terence
2008-07-10 1:07 ` Gary Scott
2008-07-10 14:10 ` Colin Paul Gloster
2008-07-10 14:57 ` fj
2008-07-10 16:47 ` Richard Maine
2008-07-10 17:03 ` Dick Hendrickson
2008-07-10 17:26 ` Craig Powers
2008-07-10 19:55 ` James Giles
2008-07-10 20:45 ` Dick Hendrickson
2008-07-10 21:22 ` Richard Maine
2008-07-10 21:29 ` Craig Powers
2008-07-10 20:45 ` Craig Powers
2008-07-10 19:51 ` James Giles
2008-07-11 15:02 ` Colin Paul Gloster
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox