From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2dd7b69b3c782182,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news.uni-jena.de!not-for-mail From: Christopher Broeg Newsgroups: comp.lang.ada Subject: Catching Ctrl-C SIGINT Date: Mon, 17 Jan 2005 13:26:06 +0100 Organization: Friedrich Schiller University Jena, Germany Message-ID: NNTP-Posting-Host: ent.astro.uni-jena.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: fsuj29.rz.uni-jena.de 1105964767 3011 141.35.25.76 (17 Jan 2005 12:26:07 GMT) X-Complaints-To: news@rz.uni-jena.de NNTP-Posting-Date: 17 Jan 2005 12:26:07 GMT User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040114 X-Accept-Language: en-us, en Xref: g2news1.google.com comp.lang.ada:7864 Date: 2005-01-17T12:26:07+00:00 List-Id: 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