From: "Robert I. Eachus" <rieachus@attbi.com>
Subject: Re: DYNAMIC ADA TASK CREATION?
Date: Thu, 19 Jun 2003 06:05:49 GMT
Date: 2003-06-19T06:05:49+00:00 [thread overview]
Message-ID: <3EF15295.5020307@attbi.com> (raw)
In-Reply-To: x7vvfv28xk3.fsf@smaug.pushface.org
Simon Wright wrote:
>>>: type ts is array (positive range <>) of ta := new t;
>>> ^^^^^^^^
> That version was Robert's ...
Let me make it official, it was a typo, should have been:
type ts is array (positive range <>) of ta := (others => new t);
But I really wanted to answer this:
Oh, why is it worse with discriminants?
There are usually in Ada implementations two types of storage associated
with tasks. The first is a task descriptor, which contains addresses
for the code, entry queues, and other such stuff. The other part is a
stack and (and possibly local heap) for the executing object. If the
task has descriminants, they are normally stored in the task descriptor.
Again in the normal case, the stack (and local heap if allocated) will
be deallocated when the task terminates. The task descriptor is the
thing that can be deallocated by Unchecked_Deallocation.
If a task without discriminants is freed before it becomes terminated,
it won't affect the executing task. But it may deallocate the task
descriptor which contains the discriminants. If the task, or any of
it's dependent tasks references the discriminants, it is a bounded
error, which will most likely cause Program_Error in the task. See RM
13.11.2(11-15) for details on other possibilities.
For a task without discriminants, you may not free all the memory that
you had hoped for, but the only real effect is that you may no longer be
able to reference the task. (Of course, calling an instance of
Unchecked_Deallocation while salting away a copy of the pointer is not
something you should do either. But that case is a lot more obvious.)
In most normal tasking programs there is no particular reason to free
the task descriptors. And as I said, the memory allocated for the stack
will go away anyway when the task is terminated. (In language lawyer
speak, a task is completed when the code execution reaches the end of
the code and in other cases. But termination waits until all dependent
tasks have become terminated. This is so that dependent tasks can still
reference the parent task's stack.)
So usually when a programmer thinks he wants to go around stomping out
tasks, he has left one or two tasks hanging that are keeping a lot of
other tasks half-alive.
next prev parent reply other threads:[~2003-06-19 6:05 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-17 19:53 DYNAMIC ADA TASK CREATION? avram
2003-06-17 20:24 ` Simon Wright
2003-06-18 6:11 ` Robert I. Eachus
2003-06-18 9:20 ` Georg Bauhaus
2003-06-18 11:13 ` John McCabe
2003-06-18 12:43 ` John McCabe
2003-06-18 14:17 ` Georg Bauhaus
2003-06-19 5:07 ` Simon Wright
2003-06-19 6:05 ` Robert I. Eachus [this message]
2003-06-19 23:30 ` Jeffrey Carter
2003-06-18 19:15 ` avram
2003-06-18 21:17 ` Craig Carey
2003-06-20 18:56 ` avram
2003-06-21 13:06 ` Pascal Obry
2003-06-18 23:28 ` Robert I. Eachus
2003-06-19 5:09 ` Simon Wright
2003-06-19 6:39 ` Robert I. Eachus
2003-06-19 20:34 ` Simon Wright
2003-06-28 0:54 ` Matthew Heaney
2003-06-28 7:25 ` Robert I. Eachus
2003-06-30 7:35 ` Dmitry A. Kazakov
2003-06-30 15:01 ` Matthew Heaney
2003-07-01 7:19 ` Dmitry A. Kazakov
2003-07-01 14:21 ` Matthew Heaney
2003-07-02 12:05 ` Mário Amado Alves
2003-07-02 19:41 ` Simon Wright
2003-07-03 21:31 ` Mário Amado Alves
2003-07-03 9:53 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox