Catching Ctrl-C SIGINT
From: Christopher Broeg (broeg_at_astro.uni-jena.de~)
Date: 01/17/05
- Next message: Alfred Hilscher: "Re: Ada equivalent for C-pointer?"
- Previous message: Matteo Bertini: "Ada-Python inter-language testing"
- Next in thread: Martin Dowie: "Re: Catching Ctrl-C SIGINT"
- Reply: Martin Dowie: "Re: Catching Ctrl-C SIGINT"
- Reply: Simon Wright: "Re: Catching Ctrl-C SIGINT"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 Jan 2005 13:26:06 +0100
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 message: Alfred Hilscher: "Re: Ada equivalent for C-pointer?"
- Previous message: Matteo Bertini: "Ada-Python inter-language testing"
- Next in thread: Martin Dowie: "Re: Catching Ctrl-C SIGINT"
- Reply: Martin Dowie: "Re: Catching Ctrl-C SIGINT"
- Reply: Simon Wright: "Re: Catching Ctrl-C SIGINT"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|