From: Christopher Broeg <broeg@astro.uni-jena.de~>
Subject: Catching Ctrl-C SIGINT
Date: Mon, 17 Jan 2005 15:07:57 +0100
Date: 2005-01-17T14:07:57+00:00 [thread overview]
Message-ID: <csggrt$54u$1@fsuj29.rz.uni-jena.de> (raw)
Hi,
I am having some trouble with protected types. I am trying to do some
cleanup work if the user presses Ctrl-C SIGINT.
For this I wrote a little test program. The problem is getting the
information about the raised interrupt back to the main program. I tried
using a little task that calls a entry in a protected type:
with Catch_Interrupt;
with Ada.Text_IO;use Ada.Text_IO;
procedure Test1 is
Stop: exception;
task Get_Info is
entry Stop;
end Get_info;
task body Get_Info is
begin
loop
Catch_Interrupt.Event.wait;
-- here comes the code that handles the interrupt received
select
accept Stop do
Stop;
end Stop;
or
terminate;
end select;
end loop;
end Get_Info;
begin
for i in 1 .. 5 loop
Put(Integer'Image(i));
delay 1.0;
end loop;
end Test1;
the package actually doing the interrupt catching is:
with Ada.Interrupts;
with Ada.Interrupts.names;
package Catch_Interrupt is
Sig_Int_Caught : exception;
procedure Signal_Public;
protected Catch_Interrupt is
procedure Clean_up;
pragma Unreserve_All_Interrupts;
--pragma interrupt_Handler(Clean_Up);
pragma Attach_Handler(Clean_Up,Ada.Interrupts.Names.SIGINT);
end Catch_Interrupt;
protected Event is
entry Wait;
procedure Signal;
private
Allowed : Boolean := False;
end Event;
end Catch_Interrupt;
with Ada.Text_IO;
use Ada.Text_IO;
package body Catch_Interrupt is
procedure Signal_Public is
begin
Event.Signal;
end Signal_Public;
protected body Catch_Interrupt is
procedure Clean_up is
begin
Put_line("Interrupt SIGINT caught. sending signal ");
Signal_public;
Put_line("SIGNAL SENT. ");
end Clean_Up;
end Catch_Interrupt;
protected body Event is
entry Wait when allowed is
begin
Put_line("catch_interrupt msg: in entry wait");
end Wait;
procedure Signal is
begin
Put_line("Signal received!!!");
Allowed := True;
end Signal;
end Event;
end Catch_Interrupt;
Here the problem:
I do get the message
"Interrupt SIGINT caught. sending signal "
but the signal_public procedure never manages to send the signal. I
don't know why. If I call the signal_public procedure from test1 it
works, but is of course useless.
Can you give me any hints on what I am doing wrong? I am lost.
Maybe there is a better way to react upon the interrupt? But still I am
wondering why my solution is not working.
Thanx a lot,
Chris
next reply other threads:[~2005-01-17 14:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-17 14:07 Christopher Broeg [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-01-17 14:13 Catching Ctrl-C SIGINT Christopher Broeg
2005-01-17 12:26 Christopher Broeg
2005-01-17 14:19 ` Martin Dowie
2005-01-17 14:35 ` Christopher Broeg
2005-01-17 21:37 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox