From: Tim McGuire <mcguire_tm2@yahoo.com>
Subject: Problem with Delay Alternative in Finalization
Date: Fri, 18 May 2012 21:30:31 -0500
Date: 2012-05-18T21:30:31-05:00 [thread overview]
Message-ID: <6v0er7d545kvs3pr7aqe1dnrlq4mg5ldhg@4ax.com> (raw)
I am porting code from Solaris to Linux.
I am running in to a problem where a delay alternive used when in
finalization doesn't seem to be working properly.
The delay part never seems to happen.
The actual code is very complex, so I wrote a simple test to see if
the problem still existed.
I know there are better ways to do what this test program does, but I
am just trying to see if I can reproduce the problem from the actual
code.
I am using GCC 4.3.4 and to compile the program I issue the following
commands:
gnatname "*.[12].ada"
gnatmake token_test.2.ada -o token_test.exe
(spec)
===========
with Ada.Finalization;
package Test_Lock_Token is
Lock_Timeout_Exception : exception;
Unknown_Exception : exception;
type Lock_Token is
Ada.Finalization.Limited_Controlled with null record;
private
procedure Initialize (Object : in out Lock_Token);
procedure Finalize (Object : in out Lock_Token);
end Test_Lock_Token;
===========
(body)
===========
package body Test_Lock_Token is
protected Lock_Type is
entry Acquire;
procedure Release;
private
Blocked : Boolean := False;
end Lock_Type;
protected body Lock_Type is
entry Acquire when (not Blocked) is
begin
Blocked := True;
end Acquire;
procedure Release is
begin
if Blocked then
Blocked := False;
else
raise Unknown_Exception;
end Release;
end Lock_Type;
procedure Initialize (Object : in out Lock_Token) is
begin
select
Lock_Type.Acquire
or
delay 2.0;
raise Lock_Timeout_Exception;
end select;
end Initialize;
procedure Finalize (Object : in out Lock_Token) is
begin
Lock_Type.Release;
end Finalize;
end Test_Lock_Token;
===========
With a main of
===========
with Ada.Text_Io;
with Test_Lock_Token;
Procedure Token_Test is
begin
declare
Token : Test_Lock_Token.Lock_Token;
begin
Ada.Text_Io.Put_Line ("Got Token");
declare
Token_2 : Test_Lock_Token.Lock_Token;
begin
Ada.Text_Io.Put_Line ("Got Token_2");
exception
When Errors : Test_Lock_Token.Lock_Timeout_Exception =>
Ada.Text_Io.Put_Line ("Token_2 timed out!");
end;
exception
When Errors : Test_Lock_Token.Lock_Timeout_Exception =>
Ada.Text_Io.Put_Line("Token timed out!");
end;
end Token_Test
===========
will lock up on the second attempt to get the token.
Why doesn't the delay happen and raise the timeout exception?
It's not practical to rewrite the code unless absolutely neccessary.
Is there some compiler directive or pragma that I need to use in order
to get the delay alternative to work properly?
Thanks,
Tim
next reply other threads:[~2012-05-19 2:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-19 2:30 Tim McGuire [this message]
2012-05-19 6:12 ` Problem with Delay Alternative in Finalization Dmitry A. Kazakov
2012-05-19 12:51 ` Tim McGuire
2012-05-19 14:04 ` Dmitry A. Kazakov
2012-05-19 19:46 ` Robert Matthews
2012-05-20 16:46 ` Tim McGuire
2012-05-20 17:01 ` Dmitry A. Kazakov
2012-05-20 20:36 ` Simon Wright
2012-05-19 17:33 ` Simon Wright
2012-05-20 6:17 ` Simon Wright
2012-05-19 20:31 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox