[GAP] Asynchroneus IO on Mac OS X

Ted Baker baker at cs.fsu.edu
Fri Sep 8 18:34:27 CEST 2006


I would be interested in hearing about the resolution of this
problem.  When I wrote the code for signal handling I do not think
I made any distinction for SIGIO.

One possibility is that the signal has been reserved.  There are
some signals that are excluded from handling by an application,
including those used by internally by the Ada runtime system and
those used by certain thread libraries.  For example, I think the
FSU thread library installs its own handler for SIGIO in order to
implement non-blocking reads and writes.  (Florist tries to
auto-configure the set of signals that can be handled by various
means, but the autoc-onfiguration cannot be 100% correct.)  If the
signal is reserved, you really should get an exception when you
try to bind a handler to it.

Another possibility is that the signal is not being generated,
because it was not enabled for that file.  I suppose that you did
remember to enable SIGIO, using fcntl?

Either way, it seems you should be able to work around this by
using fcntl with F_SETSIG to change over to a different signal.
Did you try that?

--Ted

On Fri, Sep 08, 2006 at 05:02:16PM +1000, Christfried Webers wrote:
> 
> While porting an Ada program running on Solaris and Linux to Mac OS X,
> I ran into the problem that I could not catch SIGIO signals via an 
> installed signal handler (protected procedure). Before joining the GAP, I 
> filed a report to ACT ([F411-002 public], see below), but as a public 
> member I had no way of figuring out what happened with it.
> 
> Therefore, I am still puzzled, whether there is any proper Ada way of 
> catching the SIGIO on Mac OS X?
> 
> As mentioned below, installing a handler via a C library call to 
> sigaction() can solve the problem but completely by-passes the Ada runtime 
> and that just doesn't feel right.
> 
> Best
> Chris
> 
> P.S.: My question has some relation to the previous thread:
> I choose asynchronous IO with signals in order to be able to properly 
> release (but not kill!) the reading task after a timeout if NO data is 
> coming in. With blocking IO, one just hangs on the IO call.
> 
> -------------  excerpt of [F411-002 public]  -------------------------
> 
> 1.) It seems that pragma Attach_Handler does not
> result in a SIGIO being caught. It works fine with
> other signals though. (Installing a signal handler
> for the signal via a C call to sigaction() from the
> Ada main program installs a handler which catches
> the SIGIO signal.)
> 
> I tested it via repeated
> kill -s IO   <process id>
> kill -s USR1 <process id>
> 
> and only got
> Got SIGUSR1, Counter =  1
> Got SIGUSR1, Counter =  2
> Got SIGUSR1, Counter =  3
> ...
> 
> ------------------------------------
> with Ada.Text_IO;
> with Ada.Interrupts.Names;
> with Signals;
> 
> procedure Demo is
>   use Ada.Text_IO;
>   use Ada.Interrupts;
>   use Ada.Interrupts.Names;
> 
>   SIGIO_Name    : aliased String := "SIGIO";
>   SIGIO_Monitor : Signals.Monitor(SIGIO, SIGIO_Name'Access);
> 
>   SIGUSR1_Name    : aliased String := "SIGUSR1";
>   SIGUSR1_Monitor : Signals.Monitor(SIGUSR1, SIGUSR1_Name'Access);
> 
> begin
>   loop
>      delay 1.0;
>   end loop;
> end Demo;
> 
> package Signals is
>   use  Ada.Interrupts, Ada.Interrupts.Names;
> 
>   --  Must first unreserve this interrupt if using SIGINT
>   pragma Unreserve_All_Interrupts;
> 
>   protected type Monitor (Signal : Interrupt_ID;
>                           Name   : access String) is
>      procedure Handler;
>      pragma Attach_Handler (Handler, Signal);
>   private
>      Counter : Natural := 0;
>   end Monitor;
> end Signals;
> 
> with Ada.Text_IO;
> 
> package body Signals is
>   use Ada.Text_IO;
> 
>   protected body Monitor is
>      procedure Handler is
>      begin
>         Counter := Counter + 1;
>         Put_Line ("Got " & Name.all &
>                   ", Counter = " & Counter'Img);
>      end Handler;
>   end Monitor;
> end Signals;
> ----------------------------------------------------------------------
> 
> Christfried Webers                     Department of Information Engineering
> Ph  +61 2 6125 8602    Research School of Information Sciences & Engineering
> Fax +61 2 6125 8660                    and    Department of Computer Science
> Christfried.Webers at anu.edu.au          Australian National University
> 
> 
> _______________________________________________
> GAP mailing list
> GAP at gnat.info
> /no-more-mailman.html
> To unsubscribe from this list, please contact the GAP GNAT Tracker 
> administrator
> within your organization.


More information about the GAP mailing list