Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Will a shared filehandle processed by multiple threads/processes cause problems?

by Athanasius (Archbishop)
on Jul 01, 2014 at 06:42 UTC ( [id://1091803]=note: print w/replies, xml ) Need Help??


in reply to Will a shared filehandle processed by multiple threads/processes cause problems?

Maybe I’m misunderstanding, but I don’t see why you need to share the filehandle among any of the child processes. Have the parent thread read in the file, split the data into appropriate-sized chunks (or lines, as you say), and feed each chunk to a different child process. This will avoid all the problems arising from shared filehandles, including those detailed by wrog, above, and without losing any of the potential benefits of utilising multiple cores. (Whether those benefits outweigh the additional overhead of creating and managing the child processes is another question, one which you will need to answer by profiling.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

  • Comment on Re: Will a shared filehandle processed by multiple threads/processes cause problems?

Replies are listed 'Best First'.
Re^2: Will a shared filehandle processed by multiple threads/processes cause problems?
by alanraetz (Novice) on Jul 01, 2014 at 15:37 UTC
    Yes, this was my original thought, to split up the file first and then spawn a bunch of processes for each chunk... thanks for the response. Actually my thought now is to point the script to a test input file that takes about 10 seconds to process and either do some speed profiling or just direct code optimization and see if I can speed it up. There are numerous inefficiencies in the script, so I have some ideas.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1091803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found