- Create a "master" Thread (usually the root thread).
- Create some (possibly configurable) number of child threads
- (Here's the tricky part). You've got a couple of alternatives:
- a) on thread->create(), pass the fileno() to each child thread, along with an
offset and skip count. Each child thread then does an open(INF, '<&', $fileno)
on the fileno, reads/discards skip count lines, then iteratively read/process/
skip until EOF
- b) alternately, create 2 Thread::Queues (one from master to children,
the other from children to master). Master reads each line from file
and posts to downstream queue; children grab (randomly) a line off
the queue, process it, then post a response to the upstream queue.
As ever, TIMTOWTDI. (b) is probably simpler, but (a) is more deterministic.
Both can be mimiced using a process based approach.
I've successfully used (a) for ETL tools, but if your file is
binary/random access, it can get complicated to skip records.
Also, if the children are writing to an output file, (b)
might be easier to let a single master thread do the writing
instead of coordinating writes betwen children.
Perl Contrarian & SQL fanboy
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.