Hi Goneri,
Thanks for your feedback.
The problem you found is because $pool1 and $pool2 are not shared variables across threads. Inside sub pool1, $pool2 is only a copy of initial value when pool1 creates the worker thread.
If you change the order of $pool1 = Thread::Pool::Simple->new, and $pool2 = Thread::Pool::Simple->new, you can find the problem are gone. This is because in pool1's thread, $pool2 is a initialized & valid object.
However, this is not a cure. Since anything using Thread::Pool::Simple is essentially a threads application, if you want to pass variables across threads, you should use threads::shared to declare them correctly.
if you declare $pool1 and $pool2 as following:
use threads;
use threads::shared;
use Thread::Pool::Simple;
my $pool1 : shared;
my $pool2 : shared ;
then you can find the problem are gone no matter what the order you initialize $pool1 and $pool2.
Thanks again for trying the module.
Best wishes,
J.
Show quoted text----- Original Message ----
From: Gonéri Le Bouder via RT <bug-Thread-Pool-Simple@rt.cpan.org>
Sent: Thursday, 24 May, 2007 4:49:14 PM
Subject: [rt.cpan.org #27276] fails to use more than one pool at the same time
Thu May 24 11:49:12 2007: Request 27276 was acted upon.
Transaction: Ticket created by goneri@rulezlan.org
Queue: Thread-Pool-Simple
Subject: fails to use more than one pool at the same time
Broken in: (no value)
Severity: (no value)
Owner: Nobody
Requestors: goneri@rulezlan.org
Status: new
Ticket <URL:
http://rt.cpan.org/Ticket/Display.html?id=27276 >
Hi,
First thank you for the nice Thread::Pool::Simple module.
I tried to create a more than one pool without a lot of success. I did this
little example to explain the problem:
#!/usr/bin/perl -w
use strict;
use Thread::Pool::Simple;
my $pool1;
my $pool2;
sub pool1 {
print "pool1\n";
$pool2->add();
}
sub pool2 {
print "pool2\n"; # Never printed
}
$pool1 = Thread::Pool::Simple->new(
do => [\&pool1]
);
$pool2 = Thread::Pool::Simple->new(
do => [\&pool2]
);
$pool1->add();
$pool1->join();
$pool2->join();
print "launching pool2 directly\n";
$pool2->add();
$pool2->join();
$./test.pl
pool1
launching pool2 directly
^C
The "pool2" message is never printed and trying to launch it directly create an endless while.
I think this come from the shared variable from the module (%config,
$stat and $worker) but I probably missed something.
Best regards,
Gonéri Le Bouder