--- AnyEvent/lib/AnyEvent.pm 2007/11/16 09:13:11 1.36 +++ AnyEvent/lib/AnyEvent.pm 2007/11/23 10:42:00 1.37 @@ -111,7 +111,7 @@ }); # to cancel the timer: - undef $w + undef $w; =head2 CONDITION WATCHERS @@ -254,7 +254,7 @@ use Carp; -our $VERSION = '2.6'; +our $VERSION = '2.7'; our $MODEL; our $AUTOLOAD; @@ -375,6 +375,7 @@ our %PID_CB; our $CHLD_W; +our $CHLD_DELAY_W; our $PID_IDLE; our $WNOHANG; @@ -387,6 +388,14 @@ undef $PID_IDLE; } +sub _sigchld { + # make sure we deliver these changes "synchronous" with the event loop. + $CHLD_DELAY_W ||= AnyEvent->timer (after => 0, cb => sub { + undef $CHLD_DELAY_W; + &_child_wait; + }); +} + sub child { my (undef, %arg) = @_; @@ -400,9 +409,9 @@ } unless ($CHLD_W) { - $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); - # child could be a zombie already - $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); + $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); + # child could be a zombie already, so make at least one round + &_sigchld; } bless [$pid, $arg{cb}], "AnyEvent::Base::Child"