cond_wait problem with Thread::Pool

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I had a nested loop where each iteration doesn't depend on any other iterat=
ion, so I concluded I could use Thread::Pool to queue up the iterations to =
make the loop go faster.  Each iteration makes an HTTP connection to a serv=
er, so it likely would be faster using a thread pool.

So, I moved the body of the iteration to a new sub, and added a sub paramet=
er for the two loop indices (which the iteration body needs).  The body nee=
ds to reference other data defined earlier in the script, which I left as i=
s in the new sub.

I ended up replacing the body with the following approximate line:

  $pool->enqueue(\&mynewsub, $rindex, $dindex);

The first thing I noticed were warnings like the following:

pragma "attrs" is deprecated, use "sub NAME : ATTRS" instead at /usr/lib/pe=
rl5/site_perl/5.10/Thread/ line 98.

Fortunately, this was an easy fix. was using the deprecated "use a=
ttrs". so I changed it to the newer format.  I also filed a bug report on T=
hread::Pool for this.

The next problem I don't have a fix for yet.  When it hit the loop and star=
ted enqueuing tasks, I saw the following on the console:

Thread 343 terminated abnormally: cond_wait can only be used on shared valu=
es at /usr/lib/perl5/site_perl/5.10/Thread/ line 100.

This is in the following method:

sub _next_job : locked : method {
    my $pool = shift;
    my $job = $pool->->[0];
    shift @} if defined $job;
    return $job;

I don't know if this represents a bug in Thread::Pool or some problem with =
my script.  If it matters, these are my first statements in the script:

use threads;
use threads::shared;
use Thread::Pool;

The other thing I'm wondering about with Thread::Pool is concerning what ha=
ppens at the end of my script?  Do I have to do some sort of "join()" to en=
sure all the jobs are completed?  I didn't see any way to do this in the Th=
read::Pool documentation.

Re: cond_wait problem with Thread::Pool

Note that I tried examining the sub that is being queued and traced back to=
 all of the non-local variables that sub references and added "share($var)"=
 calls after their declarations, even the declaration of my "$pool" variabl=
e (which might be a different entity than the "$pool" referenced in
), but it made no difference.  I still get the "cond_wait" error.

Re: cond_wait problem with Thread::Pool

David Karr wrote:

Quoted text here. Click to load it

Did you try running the example code that comes with the module?  If so,
did it work?

Are you marking the pool object as shared?


Site Timeline