safe signals + sub-second alarms [was: sleep(0.5) should DWIM]

2001-01-31 Thread Ken Fox

Branden wrote:
 Actually, with event loops and threading issues, probably things like
 the perl built-ins sleep and alarm won't ever be passed to the syscalls
 sleep(3) and alarm(3).

Sleep isn't usually a syscall -- it's often a library routine that sets
an alarm and blocks or uses some other general purpose syscall to block.
Perl *must* use one of these OS features unless you want to busy wait.

 Perl will probably block that instance of the
 interpreter internally and do some other stuff. It will probably use
 its internal clock to measure the time to unblock it, and that clock
 will probably have sub-second precision.

That's silly. You want perl to block a thread and then busy wait until
it's time for the thread to wake up? Even if perl has other threads
going it will be incredible wasteful to check a timer between every OP.

Lots of discussion on signal delivery has taken place and it seems like
people have agreed to have async delivery with the signal handler called
at the next "safe" opportunity -- between expression boundaries for
example. IMHO making alarm a high-resolution timer is not consistent
with safe signal delivery. If a user asks for alarm(10) and gets a signal
12 seconds later that's probably ok. If a user asks for alarm(0.005) and
gets a signal 1 second later that's a problem. (Perl isn't Java -- we
have lots of OPs that can take a long time to run.)

Basically I'm afraid of advertising high-res timers and then having
so many caveats that they aren't useful or portable. Stuff in the core
should be dependable.

- Ken

P.S. I didn't realize anybody was doing video games or device drivers
in Perl. Has anybody ever written code where the resolution of alarm was
a problem? I've only used alarm to prevent blocked I/O from hanging
servers. For graphical programs I've always used the toolkit dependent
alarm features.



Re: safe signals + sub-second alarms [was: sleep(0.5) should DWIM]

2001-01-31 Thread Ken Fox

Bart Lateur wrote:
 What if we take the ordinary sleep() for the largest part of the
 sleeping time (no busy wait), and the 4 argument select for the
 remainder, i.e. subsecond?

You're trying to solve a problem that doesn't exist.

Sleep doesn't have the signal delivery problems that alarm has,
but IMHO sleep and alarm must have identical argument semantics.
Since we can't reasonably provide sub-second alarm resolution
then sleep can't have it either.

If you need sub-second resolution and accuracy then use an
external module. It will be a tough module to implement -- and
very platform specific.

- Ken