in reply to Re^2: ithreads weren't the way.. still searching
in thread ithreads weren't the way.. still searching
What's up with your node? You can use HTML for the most part, except use <code> to wrap code, so it can be formatted and/or extracted correctly.
It shouldn't be hard to keep the order that you walk the pages in, but we'll go with the threads here. You have a few problems to deal with:
You could try an assembly-line thread pattern. Imagine thus:
I know this will need some adjustment to get exactly what you want, but you get the idea, right? (code above is pseudocode, missing much. may not even be sane, read sleep and gin disclaimer above.) I think a key part is passing the $work_queue into the fetch thread, so it can add to its own input queue.use threads; use Thread::Queue; my $work_queue = Thread::Queue->new; $work_queue->enqueue($_) for ($start .. $end); #Fill our work queue my $work_queue = Thread::Queue->new; my $fetch_thread = threads->new( \&fetch, $work_queue, $fetched_queue +); sub fetch { my $input_queue = shift; my $output_queue = shift; while ( my $fetch_this = $input_queue->dequeue ) { #Get content, put in scalar $output_queue->enqueue($content); last if ($input_queue->pending == 0) } } my $processed_queue = Thread::Queue->new; my $process_thread = threads->new( \&process, $fetched_queue, $proces +sed_queue ); sub process { my $input_queue = shift; my $output_queue = shift; while ( my $process_this = $input_queue->dequeue ) { #process data, put in scalar $output_queue->enqueue($content); last if ($input_queue->pending == 0) } } while (my $processed_data = $processed_queue->dequeue) { #Assemble into final output last if ($input_queue->pending == 0) } #Make final output
Update:Also, "fork() em" is a play on "f__k em". That is to say, ignore the warnings, and continue on your quest, noble monk!
|
---|