I don't understand this part , I think you have too many queues, and you should probably have two, one for files to process , and one for results of that processing

Also the closures don't make sense to me

The meat of the threading code :)

sub create_thread_pool { my $files_to_digest = shift; threads->create( threads_progress => $files_to_digest ); for ( 1 .. $opts->{threads} ) { my $thread_queue = Thread::Queue->new; my $worker_thread = threads->create( worker => $thread_queue ); $worker_queues->{ $worker_thread->tid } = $thread_queue; } lock $threads_init; $threads_init++; } sub get_dup_digests { my $size_dups = shift; my $dup_count = 0; my $queued = 0; $dup_count += @$_ for map { $size_dups->{ $_ } } keys %$size_dups; # creates thread pool, passing in as an argument the number of file +s # that the pool needs to digest. this is NOT equivalent to the numb +er # of threads to be created; that is determined in the options ($opt +s) create_thread_pool( $dup_count ); sub get_tid { my $tid = $pool_queue->dequeue; return $tid; } my $tid = get_tid(); SIZESCAN: for my $size ( keys %$size_dups ) { my $group = $size_dups->{ $size }; for my $file ( @$group ) { $worker_queues->{ $tid }->enqueue( $file ) if !$thread_term; $queued++; $tid = get_tid() and $queued = 0 if $queued == $opts->{qsize} + - 1; last SIZESCAN unless defined $tid; } } # wait for threads to finish while ( $d_counter < $dup_count ) { usleep 1000; # sleep for 1 millisecond } # ...tell the threads to exit end_wait_thread_pool(); # get rid of non-dupes delete $digests->{ $_ } for grep { @{ $digests->{ $_ } } == 1 } keys %$digests; my $priv_digests = {}; # sort dup groupings for my $digest ( keys %$digests ) { my @group = @{ $digests->{ $digest } }; $priv_digests->{ $digest } = [ sort { $a cmp $b } @group ]; } undef $digests; return $priv_digests; }

In reply to Re: Threaded Code Not Faster Than Non-Threaded -- Why? (meat) by Anonymous Monk
in thread Threaded Code Not Faster Than Non-Threaded -- Why? by Tommy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.