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...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.