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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.bbs-scene.org!xmission!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: 4 beginner's questions on the PL Ada Date: Fri, 09 Aug 2013 19:40:47 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <87ob96ajv6.fsf@VLAN-3434.student.uu.se> <03ea570b-e45f-4694-ab9b-3413c4770379@googlegroups.com> <878v0aee8i.fsf@VLAN-3434.student.uu.se> <87ob96cxm8.fsf@VLAN-3434.student.uu.se> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1376091647 5281 192.74.137.71 (9 Aug 2013 23:40:47 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 9 Aug 2013 23:40:47 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:wJGei+KHvPdM7vnb4nAwWKb1gI4= X-Original-Bytes: 3516 Xref: number.nntp.dca.giganews.com comp.lang.ada:182914 Date: 2013-08-09T19:40:47-04:00 List-Id: Alan Jump writes: > On Friday, August 9, 2013 3:36:52 PM UTC-7, Robert A Duff wrote: >> X := new Some_Task_Type; >> X := new Some_Task_Type; >> X := new Some_Task_Type; >> >> You get three heap-allocated tasks, with nothing in the Image >> to distinguish them other than the TCB address. > > Umm...I'm a neophyte when it comes to Ada, but the example you gave > doesn't register with me as being valid. It allocates three tasks, which will run concurrently with each other, and with the task doing these allocations. There's a memory leak here (the first two allocated task objects can never be Unchecked_Deallocated), but that's not relevant to the questions about Image. So perhaps a more realistic example would be: for X in Index range 1..3 loop Some_Array(X) := new Some_Task_Type; end loop; Or the tasks could be chained in a linked list, or whatever. In any case, they run concurrently, and they terminate when they get to their "end", or raise an unhandled exception, or when a "terminate" alternative is selected. The master that owns the access type will wait for them to terminate -- probably after the main procedure returns. >...I read that as three separate > allocations in a row of Some_Task_Type to the same variable name, and > logic would tell me that with each new allocation, the previous > allocation terminates, with questionable (and likely > implementation-specific) grace. Not sure what you mean by "allocation terminates". The allocator returns a pointer to a task, which will run until it is done -- it depends what's in the task body. In many embedded systems, tasks have infinite loops and never terminate. There's nothing questionable, implementation specific, or ungraceful here, other than the memory leak I mentioned, and the fact that Image is defined to be implementation specific. >...Would that not result in each > allocation generating its own unique 'Image(Current_Task) result? I think that in GNAT, the Image of those three tasks will be something like "Some_Task_Type_0ABC1230", where the "0ABC1230" part is different for each. So yes, they're unique, but the OP was thinking of chopping that part off before printing it out. - Bob