FFI & Interrupted System Calls...

Ivo Rössling iroess at cs.uni-magdeburg.de
Wed May 28 05:29:12 UTC 2003


Hi there!

I have a problem...

Mhhh... where should I start... ?!

Well, I am trying to write a package for Squeak that takes use of 
external libs via FFI.
As their purpose is to access physical devices, some of the system calls 
might take a
while...
So, when one of those system calls is indeed slow and a signal arrives 
while it was blocked,
waiting for something, the call is aborted and returns |-EINTR|, so that 
the library function
will return -1 and set |errno| to |EINTR|.
And unfortunately exactly this happens! In most of the cases those 
functions abort with a
"Interrupted system call".

As I figured out by examining the Unix platform code, Squeak uses a 
SIGALARM signal to
increase an internal low resolution millisecond clock.
Obviously the system calls named above get interrupted by exactly this 
signal and abort.
Of course, I could try to do something like:
--------------- snip ---------------
 while (((status=mySystemCall()) < 0) && (errno == EINTR));
--------------- snap ---------------
,but unfortunately I doubt that I can assure the system call ever to 
return a result
BEFORE getting interrupted. Sometimes it DID return the result requested 
- but there's
still a chance for the library function never (or at least: quite 
tardily) to return
from this while-loop above, isn't it?!

So - is there a way to get around this interrupt? (Disabling the 
"low-res clock" for
this particular time frame doesn't sound reasonable for me, and I'm even 
not sure if
that's possible...)

I'm looking forward for someone with an idea or solution... :-)

Cheers,
Ivo.

P.S.: During all those debuggings I also figured out that by setting an 
new sigaction
handler for this SIGALARM signal, Squeaks internal handler is going to 
be "overridden"
by former one. This in turn would cause the user's signal-handler to be 
"flooded" by
the timer interrupt every 20ms on the one hand, and Squeaks low-res 
clock not to be
updated again from that moment on, on the other... Don't know if that 
should rather be
mentioned somewhere, as this problem could not only confuse the users 
external code
(- either by means of platform specific plugin code or the usage of 
external libs via
ffi... -), but also Squeak in addition... (?!?)



More information about the Squeak-dev mailing list