Skip Menu |

This queue is for tickets about the Thread-Pool-Simple CPAN distribution.

Report information
The Basics
Id: 27276
Status: resolved
Priority: 0/
Queue: Thread-Pool-Simple

People
Owner: Nobody in particular
Requestors: goneri [...] rulezlan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: fails to use more than one pool at the same time
Date: Thu, 24 May 2007 17:49:57 +0200
To: bug-Thread-Pool-Simple [...] rt.cpan.org
From: Gonéri Le Bouder <goneri [...] rulezlan.org>
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
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #27276] fails to use more than one pool at the same time
Date: Thu, 24 May 2007 09:41:43 -0700 (PDT)
To: bug-Thread-Pool-Simple [...] rt.cpan.org
From: Jianyuan Wu <jw [...] main.cc>
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
Subject: Re: [rt.cpan.org #27276] fails to use more than one pool at the same time
Date: Thu, 24 May 2007 19:31:44 +0200
To: Jianyuan Wu via RT <bug-Thread-Pool-Simple [...] rt.cpan.org>
From: Gonéri Le Bouder <goneri [...] rulezlan.org>
On Thu, May 24, 2007 at 12:43:37PM -0400, Jianyuan Wu via RT wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=27276 > > > 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.
Thank you for your fast anwser. This fixed the first issue for me but not the second. My script seems to be in an endless while after the: "launching pool2 directly" Best regards, Gon�ri
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #27276] fails to use more than one pool at the same time
Date: Thu, 24 May 2007 11:07:24 -0700 (PDT)
To: bug-Thread-Pool-Simple [...] rt.cpan.org
From: Jianyuan Wu <jw [...] main.cc>
Is this because you called $pool->join() twice? The behaviour is undefined, as the pool is supposed to end its life-cycle after join(). Regards, 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 6:29:36 PM Subject: Re: [rt.cpan.org #27276] fails to use more than one pool at the same time Queue: Thread-Pool-Simple Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=27276 > On Thu, May 24, 2007 at 12:43:37PM -0400, Jianyuan Wu via RT wrote:
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=27276 > > > 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.
Thank you for your fast anwser. This fixed the first issue for me but not the second. My script seems to be in an endless while after the: "launching pool2 directly" Best regards, Gon�ri
Set status to resolved. Explanation was given in earlier email.