rekoil has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on an app based around POE, using POE::Component::Pool::Thread to spin individual tasks (authentication processing) to thread pools, while using a $kernel->delay event to do a regularly scheduled config check/update in its own thread, so that it doesn't block on other requests. Current state of the code is that I'm able to pass the config_update task to a thread, but I run into an issue where I depend on the callback handler to set up a subsequent $kernel-> delay event. Relevant code snippet (the other POE tasks/wheels are removed, but there are others):
$my wait_time = XX :shared; ... $heap->{update_config_threads} = POE::Component::Pool::Thread- +>new( # Only one thread at a time...just needs to be nonblocking f +or other stuff MinFree => 1, MaxFree => 1, MaxThreads => 1, StartTheads => 1, Name => 'UpdateThread', EntryPoint => \&update_child, CallBack => \&update_result_handler, ); $kernel->delay(config_check => $wait_time); }, got_input => sub { my ($kernel, $heap) = @_[KERNEL, HEAP]; my $input_line = $_[ARG0]; #print "DEBUG: \$input_line = $input_line\n"; $kernel->post(InputThread => run => $input_line); }, config_check => sub { my ($kernel, $heap) = @_[KERNEL, HEAP]; # Pass $kernel in so callback handler can get it and post new +$kernel->delay after we're finished $kernel->post(UpdateThread => run => ($kernel, $config)); }, } ); sub update_child { my ($kernel, $input) = @_; # BUILD_NEW_CONFIG HERE return ($kernel, $new_config); } sub update_result_handler { my ($kernel, $config = @_[ ARG0, ARG1 ]; # COPY_CONFIG_TO_SHARED_VAR HERE # Then post new $kernel->delay for next update check $kernel->delay(config_check => $wait_time); }
Makes sense, I hope - however, this falls over because it doesn't want to allow me to pass $kernel to the thread handler. When I run the script, I get the following error at the delay interval:
Invalid value for shared scalar at /usr/local/share/perl/5.8.7/POE/Com +ponent/Pool/Thread.pm line 183.
However, if I post the $kernel->delay *inside* the config_check event, everything works normally. However, I don't want to schedule the new check until the old one is complete, in case of concurrency issues (updating the config could take a while). Any advice here? TIA...