Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Splitting large array for threads.

by Preceptor (Deacon)
on Jun 18, 2014 at 16:59 UTC ( #1090321=note: print w/replies, xml ) Need Help??

in reply to Splitting large array for threads.

A few points if I may?

  • Don't enqueue 'undef', use the 'end()' method to Thread::Queue. Much neater.
  • What are you trying to accomplish with 'pos'? Because it's a race condition. You lock it and update it, but a thread may - or may not - have already dequeued and read the variable .
  • You don't really need that 'eof' test, as it's implicit in reading 'FILE'. You might be better off with a while loop there.
  • 'use strict' is good. 'use warnings' is good too.

I can't see why your process would be stalling though. Usually I would look for an empty queue or a lock. Can I suggest inserting:

$Q -> pending();

Into that loop, for the sake of verification. My guess is that you might be getting tripped up by that 'sleep' call. But can't tell for sure, because it seems to work ok with an 1800 line file.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090321]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-06-21 01:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.