in reply to Output Queue from Multiple Threads

The simplest solution to the memory growth problem is to bound the size of the queue in the writers:

use constant LIMIT => 1000; sub pause { my $delay = shift; select '','','', $delay; } sub workerSub { my ($workerQueue,$outputQueue) = @_; while (my $computer = $workerQueue->dequeue()) { ## SSH command retrieving grep results and processing pause( 0.01 ) while $outputQueue->pending > LIMIT; $outputQueue->enqueue($results); } }

For a slightly more sophisticated approach, take a look at my self-limiting queue implementation:threads::Q


Anyone got any experience of this phone's predecessor?

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^2: Output Queue from Multiple Threads
by bigbot (Beadle) on Jul 31, 2015 at 15:07 UTC
    OK great thanks Browser, I see your posts all the time and they are a huge help with threads! So aside from that you don't see any obvious issues with that example?
      So aside from that you don't see any obvious issues with that example?

      This looks suspect to me: $outputQueue->enqueue(undef); If the intent of the undef is to terminate the output sub loop, pushing it before the output has been queued ain't gonna work.

      And this: $workerQueue->engueue($_) foreach @computer; tells me you haven't run the code you posted; so ...


      Anyone got any experience of this phone's predecessor?

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!