comp.lang.ada
 help / color / mirror / Atom feed
* 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

* 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

* Re: Signal handler blocks proteced type
  2004-03-25 17:05 Lutz Donnerhacke
@ 2004-03-26 10:00 ` Lutz Donnerhacke
  2004-03-26 17:12   ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: Lutz Donnerhacke @ 2004-03-26 10:00 UTC (permalink / raw)


* Lutz Donnerhacke wrote:
> 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?

Ada.Interrupts.Detach_Handler is broken. It does not return if the signal
was delivered.

Changing the example to 'pragma Interrupt_Handler' and an explicit
Attach_Handler works fine (termination of the enviroment task succeeds).

Any call to Detach_Handler after a signal delivery results in a blocking
runtime call.

 select
    delay 2.0;
 else abort
    Detach_Handler(SIGHUP);
 end select;

does not work. Even an Abort_Task call from an other task has no effect.

The runtime (Linux-Threads) seems to miss an SIGCHILD and waits forever for
the wrong clone.



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

* Re: Signal handler blocks proteced type
  2004-03-26 10:00 ` Lutz Donnerhacke
@ 2004-03-26 17:12   ` Florian Weimer
  2004-03-27 17:45     ` Simon Wright
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2004-03-26 17:12 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> writes:

> The runtime (Linux-Threads) seems to miss an SIGCHILD and waits
> forever for the wrong clone.

I can't reproduce it on Debian/unstable (GCC 3.3.3, GNU libc 2.3.2,
Linux 2.6.4).

-- 
Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: postino.it, tiscali.co.uk, tiscali.cz, tiscali.it,
voila.fr.



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

* Re: Signal handler blocks proteced type
  2004-03-26 17:12   ` Florian Weimer
@ 2004-03-27 17:45     ` Simon Wright
  2004-03-27 23:38       ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2004-03-27 17:45 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> writes:

> I can't reproduce it on Debian/unstable (GCC 3.3.3, GNU libc 2.3.2,
> Linux 2.6.4).

Still present on a home-compiled 5.02a.



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

* Re: Signal handler blocks proteced type
  2004-03-27 17:45     ` Simon Wright
@ 2004-03-27 23:38       ` Florian Weimer
  2004-03-28 10:27         ` Simon Wright
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2004-03-27 23:38 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> Florian Weimer <fw@deneb.enyo.de> writes:
> 
> > I can't reproduce it on Debian/unstable (GCC 3.3.3, GNU libc 2.3.2,
> > Linux 2.6.4).
> 
> Still present on a home-compiled 5.02a.

It probably depends on the underlying threading implementation.  Which
one are you using?

-- 
Current mail filters: many dial-up/DSL/cable modem hosts, and the
following domains: postino.it, tiscali.co.uk, tiscali.cz, tiscali.it,
voila.fr.



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

* Re: Signal handler blocks proteced type
  2004-03-27 23:38       ` Florian Weimer
@ 2004-03-28 10:27         ` Simon Wright
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Wright @ 2004-03-28 10:27 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> writes:

> Simon Wright <simon@pushface.org> writes:
> 
> > Florian Weimer <fw@deneb.enyo.de> writes:
> > 
> > > I can't reproduce it on Debian/unstable (GCC 3.3.3, GNU libc 2.3.2,
> > > Linux 2.6.4).
> > 
> > Still present on a home-compiled 5.02a.
> 
> It probably depends on the underlying threading implementation.
> Which one are you using?

Whatever comes with a stock Intel Mandrake 8.2! (ie, not the new one).

-- 
Simon Wright                               100% Ada, no bugs.



^ 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:03 Signal handler blocks proteced type Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2004-03-25 17:05 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

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