in reply to Using select and IO::Select
duff++, good job and much needed.
One of the great things about select is its efficiency. Instead of busying around a polling loop, select lets your process go to sleep until there is something to do. That does not speed up the process where select is, but rather frees its time slice for all the other processes you and other users may run. It's the neighborly thing to do, and good for throughput.
There are some more questions I think could be covered. I don't necessarily know the answers.
(Added) This it readily checked with a few one-liners.
shows that setting timeout in select does not interfere with SIGALRM and that signals will awake pending select.$ perl -e'alarm 1;printf "Num: %d\tTime left: %f\n", select undef, und +ef, undef, 3.0' Alarm clock $
shows that having an alarm set does not interfere with select timing.$ time perl -e'alarm 5;printf "Num: %d\tTime left: %f\n", select undef +, undef, undef, 3.0' Num: 0 Time left: 0.000000 $
shows that catching a signal will jolt select into returning with -1 in the number slot. On Linux the time left value would be useful in graceful recovery from such interruptions.$ perl -e'$SIG{ALRM}=sub {};alarm 1;printf "Num: %d\tTime left: %f\n", + select undef, undef, undef, 3.0' Num: -1 Time left: 2.000000 $
(Added) Truth or not of the number tells whether the return from select was due to a timeout. As we saw, -1 means return due to interruption by catching signal. The number can be decremented with each channel handled to enable a quick test for completion. The timeleft value appears to be useful only on Linux.
$ perl -e'printf "OS: %s\tNum: %d\tTime left: %f\n", $^O, select undef, undef, undef, 1.5'
gives for several systems,
OS: linux Num: 0 Time left: 0.000000 (Zaxo)
OS: freebsd Num: 0 Time left: 1.500000 (sporty)
OS: solaris Num: 0 Time left: 1.500000 (sporty)
Thanks to sporty for his assistance with that.
Again, this is a very good job, and welcome information. You can run your pod through pod2html to get a good format for posting here.
After Compline,
Zaxo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using select and IO::Select
by tachyon (Chancellor) on Jul 05, 2004 at 00:46 UTC | |
Re^2: Using select and IO::Select
by duff (Parson) on Jul 06, 2004 at 14:41 UTC |