comp.lang.ada
 help / color / mirror / Atom feed
* Signal handler blocks proteced type
@ 2004-03-25 17:05 Lutz Donnerhacke
  2004-03-26 10:00 ` Lutz Donnerhacke
  0 siblings, 1 reply; 7+ messages in thread
From: Lutz Donnerhacke @ 2004-03-25 17:05 UTC (permalink / raw)


The following test program shows a strange behavior:

A protected type with a signal handler is instantiated in order to catch a
signal. If the signal is not catched, everything works fine. If the signal
was delivered, the inner scope will not be terminated, because the protected
type can not be finalized.

Why?

Ok, there is a zombie afterwards.
\f
with Ada.Text_IO;  use Ada.Text_IO;
with Ints;

procedure t is
begin
   Put_Line("Enviroment started.");
   declare
      i : Ints.Int;
   begin
      Put_Line("Waiting.");
      delay 2.0;
      if i.Found then
         Put_Line("Catched.");
      else
         Put_Line("Nothing.");
      end if;
   end;
   Put_Line("Enviroment stopped.");
end t;
\f
Example:
$ ./t
Enviroment started.
Waiting.
Nothing.
Enviroment stopped.

$ ./t & sleep 1; kill -1 %1; sleep 3
[1] 2366
Enviroment started.
Waiting.
Catched.
$ jobs
[1]+  Running                 ./t &
$ pstree
     |-sh-+-pstree
     |    `-t---(t)

\f
with Ada.Interrupts.Names;   use Ada.Interrupts.Names;

package Ints is
   protected type Int is
      procedure Signal;
      pragma Attach_Handler(Signal, SIGHUP);
      procedure Reset;
      function Found return Boolean;
   private
      catched : Boolean := False;
   end Int;
end Ints;
\f
package body Ints is
   protected body Int is
      procedure Signal is
      begin
	 catched := True;   
      end Signal;
      
      procedure Reset is
      begin
	 catched := False;   
      end Reset;
      
      function Found return Boolean is
      begin
	 return catched;   
      end Found;
   end Int;
end Ints;



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Signal handler blocks proteced type
@ 2004-03-25 17:03 Lutz Donnerhacke
  0 siblings, 0 replies; 7+ messages in thread
From: Lutz Donnerhacke @ 2004-03-25 17:03 UTC (permalink / raw)


The following test program shows a strange behavior:

A protected type with a signal handler is instantiated in order to catch a
signal. If the signal is not catched, everything works fine. If the signal
was delivered, the inner scope will not be terminated, because the protected
type can not be finalized.

Why?




\f
with Ada.Text_IO;  use Ada.Text_IO;
with Ints;

procedure t is
begin
   Put_Line("Enviroment started.");
   declare
      i : Ints.Int;
   begin
      Put_Line("Waiting.");
      delay 2.0;
      if i.Found then
         Put_Line("Catched.");
      else
         Put_Line("Nothing.");
      end if;
   end;
   Put_Line("Enviroment stopped.");
end t;
\f
Example:
$ ./t
Enviroment started.
Waiting.
Nothing.
Enviroment stopped.

$ ./t & sleep 1; kill -1 %1; sleep 3
[1] 2366
Enviroment started.
Waiting.
Catched.
$ jobs
[1]+  Running                 ./t &

\f
with Ada.Interrupts.Names;   use Ada.Interrupts.Names;

package Ints is
   protected type Int is
      procedure Signal;
      pragma Attach_Handler(Signal, SIGHUP);
      procedure Reset;
      function Found return Boolean;
   private
      catched : Boolean := False;
   end Int;
end Ints;
\f
package body Ints is
   protected body Int is
      procedure Signal is
      begin
	 catched := True;   
      end Signal;
      
      procedure Reset is
      begin
	 catched := False;   
      end Reset;
      
      function Found return Boolean is
      begin
	 return catched;   
      end Found;
   end Int;
end Ints;



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-03-28 10:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-25 17:05 Signal handler blocks proteced type Lutz Donnerhacke
2004-03-26 10:00 ` Lutz Donnerhacke
2004-03-26 17:12   ` Florian Weimer
2004-03-27 17:45     ` Simon Wright
2004-03-27 23:38       ` Florian Weimer
2004-03-28 10:27         ` Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
2004-03-25 17:03 Lutz Donnerhacke

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