comp.lang.ada
 help / color / mirror / Atom feed
From: jimmaureenrogers@worldnet.att.net (Jim Rogers)
Subject: Re: Problem with access parameter
Date: 25 May 2004 07:00:48 -0700
Date: 2004-05-25T07:00:48-07:00	[thread overview]
Message-ID: <82347202.0405250600.2a911b52@posting.google.com> (raw)
In-Reply-To: 5d6fdb61.0405250252.3a1f1f68@posting.google.com

402450@cepsz.unizar.es (Jano) wrote in message news:<5d6fdb61.0405250252.3a1f1f68@posting.google.com>...
> Hi,
> 
> I'm trying to finalize data inside a protected type, using the
> approach pasted at the end. I'm not sure if I get this bizarre error
> because of a Gnat 3.15p bug or because what I'm trying is illegal:
> 
> agpl-counter-multi.ads:59:04: expected an access type with designated
> type "Object" defined at line 59
> agpl-counter-multi.ads:59:04: found an access type with designated
> type derived from "Object" defined at line 59
> agpl-counter-multi.ads:59:04:   ==> in call to "_Init_Proc" at line 73
> 
> The package code is: (trimmed)
> 
> package Agpl.Counter.Multi is
> 
>    type Object;
>    type Object_Access is access all Object;
> 
>    type Destructor_Type (Parent : access Object) is limited private; 

The discriminant type is not the same as Object_Access. It is an
anonymous type. If you want to use Object_Access as the discriminant type
then specify this clearly.

> 
>    ----------------------------------------------------------------
>    -- Object                                                     --
>    ----------------------------------------------------------------
>    protected type Object is
>       -- Things
>    private
>       procedure Destroy;
>       Destructor : Destructor_Type (Object'Access);

Object is the name of a type. You cannot take the access value of a type,
only of an instance.

It looks like you are trying to create something equivalent to a C++ or Java
"this" reference. What are you trying to achieve?

>       Values     : Counter_Map.Container_Type;
>    end Object;
> 
> private
> 
>    type Destructor_Type (Parent : access Object) is new   
>    Finalization.Limited_Controlled with null record;
> 
>    procedure Finalize (This : in out Destructor_Type);
>    -- Here call to This.Parent.Destroy;

You are trying to destroy a protected object from within itself. 
Such an operation can cause a large number of problems. What happens to
tasks waiting in an entry queue for the protected object? Are they
released from the queue? I do not believe the Ada Reference Manual
specifies the results of such an operation.

> 
> end Agpl.Counter.Multi;

Remember that Ada protected objects are used as communication buffers between
two or more tasks. Destroying a protected object because of a finalization
call on one of its members appears to be a very wobbly design.

Jim Rogers



  reply	other threads:[~2004-05-25 14:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-25 10:52 Problem with access parameter Jano
2004-05-25 14:00 ` Jim Rogers [this message]
2004-05-25 15:32   ` Dmitry A. Kazakov
2004-05-25 14:58 ` Jano
2004-05-25 15:48 ` Jano
2004-05-26  7:05   ` Martin Krischik
2004-05-26 14:35     ` Jano
2004-05-26 16:11       ` Martin Krischik
2004-05-27  9:01         ` Jano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox