comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Interrupt handler and Ada.Real_Time.Timing_Events
Date: Fri, 15 May 2009 09:54:17 -0700 (PDT)
Date: 2009-05-15T09:54:17-07:00	[thread overview]
Message-ID: <e71421db-5711-48e7-bccb-e2c2f1f12e3e@f41g2000pra.googlegroups.com> (raw)
In-Reply-To: guk532$u44$1@news.motzarella.org

On May 15, 9:26 am, Reto Buerki <r...@codelabs.ch> wrote:
> Hi,
>
> I hit a rather strange issue today mixing signal/interrupt handling with
> Ada.Real_Time.Timing_Events. We have a real life application where we
> use timing events but we also need a signal handler to catch signals
> from the environment (SIGTERM etc.).
>
> I wrote a small reproducer to illustrate the problem. The following
> protected object is used as an interrupt handler, which can be attached
> to a specific interrupt/signal:
>
> with Ada.Interrupts;
>
> package Handlers is
>
>    protected type Signal_Handler (Signal : Ada.Interrupts.Interrupt_ID)
>    is
>       pragma Interrupt_Priority;
>
>       entry Wait;
>    private
>       procedure Handle_Signal;
>       pragma Attach_Handler (Handle_Signal, Signal);
>
>       Occured : Boolean := False;
>    end Signal_Handler;
>
> end Handlers;
>
> package body Handlers is
>
>    protected body Signal_Handler is
>       procedure Handle_Signal is
>       begin
>          Occured := True;
>       end Handle_Signal;
>
>       entry Wait when Occured is
>       begin
>          if Wait'Count = 0 then
>             Occured := False;
>          end if;
>       end Wait;
>    end Signal_Handler;
>
> end Handlers;
>
> The handler is used like this:
>
> with Ada.Text_IO;
> with Ada.Interrupts.Names;
>
> --  Uncommenting the next line breaks interrupt handler
> --  with Ada.Real_Time.Timing_Events;
>
> with Handlers;
>
> procedure Interrupt_Problem is
>    use Ada.Interrupts;
>
>    Handler : Handlers.Signal_Handler (Signal => Names.SIGTERM);
> begin
>
>    if Is_Attached (Interrupt => Names.SIGTERM) then
>       Ada.Text_IO.Put_Line ("Attached handler to SIGTERM");
>    else
>       Ada.Text_IO.Put_Line ("Could not attach to SIGTERM!");
>       return;
>    end if;
>
>    Handler.Wait;
>    Ada.Text_IO.Put_Line ("Interrupt received ...");
>
> end Interrupt_Problem;
>
> As expected, when sending SIGTERM to the running 'Interrupt_Problem'
> process "Interrupt received ..." is displayed. So far so good.
>
> As commented in the source code, as soon as the
> Ada.Real_Time.Timing_Events package is with'ed, this mechanism breaks.
>
> The signal handler is not invoked any more when I send a SIGTERM signal
> to a running 'Interrupt_Problem' process, it just terminates without
> triggering the Handler.Wait.
>
> What could be the cause for this behavior?

My guess would be that when Ada.Real_Time.Timing_Events is with'ed,
this causes elaboration code for the Timing_Events package to be
executed (before Interrupt_Problem), and there must be something that
this elaboration does that interferes with the Attach_Handler
mechanism.  I can't find anything in the language definition of
Timing_Events that would cause this, so it must be a problem
particular to your Ada compiler implementation, and you should contact
the vendor, or at least let us know what compiler you're using so that
others who may have some knowledge of that particular compiler might
be able to help.


> Is there a problem with this
> code?

Yes, definitely: "occurred" is misspelled.  It has two R's.  I happen
to know this one very well because I blew this word (or another form,
like "occurrence") in my 8th-grade spelling bee by only putting one R
in it.  So you've brought up some memories here.......

                               -- Adam




  reply	other threads:[~2009-05-15 16:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-15 16:26 Interrupt handler and Ada.Real_Time.Timing_Events Reto Buerki
2009-05-15 16:54 ` Adam Beneschan [this message]
2009-05-15 23:24   ` Reto Buerki
2009-05-15 16:56 ` Ludovic Brenta
2009-05-15 23:24   ` Hibou57 (Yannick Duchêne)
2009-05-16  0:20   ` Reto Buerki
2009-05-16  0:38     ` Jeffrey R. Carter
2009-05-29 15:59       ` Reto Buerki
2009-05-16  6:28 ` sjw
2009-05-16 11:05 ` Timing Example was " anon
replies disabled

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