with System.Storage_Elements;
package System.Storage_Pools is
pragma Preelaborate(System.Storage_Pools);
abstract new Ada.Finalization.Limited_Controlled with private;
Pool : in out Root_Storage_Pool;
Storage_Address : out Address;
Size_In_Storage_Elements : in Storage_Elements.Storage_Count;
Alignment : in Storage_Elements.Storage_Count) is abstract;
Pool : in out Root_Storage_Pool;
Storage_Address : in Address;
Size_In_Storage_Elements : in Storage_Elements.Storage_Count;
Alignment : in Storage_Elements.Storage_Count) is abstract;
return Storage_Elements.Storage_Count is abstract;
... -- not specified by the language
end System.Storage_Pools;
for T'Storage_Pool use Pool_Object;
(Pool_Size : Storage_Elements.Storage_Count;
Block_Size : Storage_Elements.Storage_Count)
is new Root_Storage_Pool with limited private;
Block_Size => 100);
for Acc'Storage_Pool use MR_Pool;
...
... --Allocate objects using "new Designated(...)".
Release(MR_Pool); --Reclaim the storage.
type Object(<>) is limited private;
type Name is access Object;
procedure Ada.Unchecked_Deallocation(X : in out Name);
pragma Convention(Intrinsic, Ada.Unchecked_Deallocation);
pragma Preelaborate(Ada.Unchecked_Deallocation);
new Ada.Unchecked_Deallocation(
object_subtype_name, access_to_variable_subtype_name);
package P is
new Ada.Finalization.Limited_Controlled with private;
procedure Finalize(Object : in out My_Controlled);
type My_Controlled_Access is access My_Controlled;
X : Integer := 0;
A : array(Integer range 1..10) of Integer;
begin
X := X + 1;
--If the system decides to do a garbage collection here,
--then we're in trouble, because it will call Finalize on
--the collected objects; we essentially have two threads
--of control erroneously accessing shared variables.
--The garbage collector behaves like a separate thread
--of control, even though the user hasn't declared
--any tasks.
A(X) := ...;
end Non_Reentrant;
begin
Non_Reentrant;
end Finalize;
end P;
procedure Main is
begin
... new My_Controlled ... --allocate some objects
... forget the pointers to some of them, so they become garbage
Non_Reentrant;
end Main;