[GAP] Asynchroneus IO on Mac OS X
Christfried Webers
christfried.webers at ieee.org
Sat Sep 9 10:26:36 CEST 2006
Alex,
this might be an idea but it probably needs to call C libraries
thereby bypassing the Ada runtime. I would strongly prefer to
find a solution within Ada because this will result in better
portability, stability and - well it is just nicer.
I have it already running by installing my own handler calling
sigaction().
But there is a subtle difference when using Ada, as far as I
understand. A protected procedure attached to a signal/interrupt
will be blocked if another entry of the same protected object
is active.
If my task reading data waits on the entry Wait in the
example below and a signal comes through, the task waiting
at Wait will become unblocked. While it
is resetting the Got_Signal := False, the signal delivery
via the procedure Set is blocked for the next signal. This
ensures that the flag Got_Interrupt is exclusively written
to by either the one or the other routine.
Now, if I use C library calls then the signal will just trigger
the Set procedure because it does not know anything about the Ada
runtime. So it may write to the flag Got_Interrupt concurrently
with the body of Wait. (That is probably not a big problem as long
as the flags can be written atomically.) But that is one of the
reasons why I think bypassing the Ada runtime is not a good idea.
Best
Chris
protected body Monitor is
procedure Set;
entry Wait;
private
Got_Interrupt : Boolean := False;
end Monitor;
protected body Monitor is
procedure Set is
begin
Got_Interrupt := True;
end Set;
entry Wait when Got_Signal is
begin
Got_Signal := False;
end Wait;
end Monitor;
--On 8 September 2006 9:16:47 +0200 "Alejandro R. Mosteo"
<alejandro at mosteo.com> wrote:
> I'm throwing an idea, I'm not sure if it is doable, as another
> alternative method for your problem. Use some "select" package to
> simultaneously wait for IO on your desired data source and another
> descriptor, used internally by your program to signal the timeout. You
> can thus block in the select call and interrupt the IO in a controlled
> way.
>
> If you were using sockets you already have this in Gnat.Sockets, in other
> case I'm not aware of a select packet.
>
> Best,
>
> Alex.
More information about the GAP
mailing list