The following program demonstrates a bug I found in POE v0.22 . I
was trying to benchmark event calling (inline_states vs. package_states
vs. object_stats). The benchmark program took a long time the the first
test and then exited quickly on the second and following tests.

It turns out that for the first time $poe_kernel->run() is called
the 'iterate' event will be called 11 times (as is expected). However,
on the second call to $poe_kernel->run(), the 'iterate' event handler
will only be run twice. The '_start' handler posts an 'iterate' event
and it is executed by the kernel. The 'iterate' handler yields an
'iterate' event and it is run. But the second yield to 'iterate'
from the 'iterate' handler fails to be executed.

The workaround I found was that if you use the Event module the sessions
executes correctly twice. I haven't had the time to chase down the real
cause.

BTW, I found the bug on Redhat 7.3 with perl v5.6.1 and POE v0.22 .

--- begin ---
#!/usr/bin/perl

use strict;
use warnings;

#use Event;
use POE;

my $MAX = 10;
my $VERBOSE = 1;

for (0..1) {
  POE::Session->create
      (
       inline_states =>
       {
        _start => sub {
          $_[HEAP]->{i} = 0;
          $_[HEAP]->{max} = $_[ARG0];
          $_[KERNEL]->yield('iterate');
          print STDERR "_start i=",$_[HEAP]->{i},"; max=",$_[HEAP]->{max},";\n"
            if $VERBOSE;
        },
        _stop => sub {
          print STDERR "_stop\n" if $VERBOSE;
        },
        iterate => sub {
          if ($_[HEAP]->{i} < $_[HEAP]->{max}) {
            $_[HEAP]->{i}++;
            $_[KERNEL]->yield('iterate');
            print STDERR "yield(iterate)\n" if $VERBOSE;
          }
          print STDERR "iterate i=",$_[HEAP]->{i},"; max=",$_[HEAP]->{max},";\n"
            if $VERBOSE;
        }
       },
       args => [ $MAX ]
      )
        or die "Failed to create main inline session";

  $poe_kernel->run();
}

exit 0;
--- end ---

Reply via email to