Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: MultiThreaded Program in perl

by BrowserUk (Pope)
on Nov 10, 2010 at 00:07 UTC ( #870440=note: print w/replies, xml ) Need Help??

in reply to MultiThreaded Program in perl


#! perl -slw use strict; use threads; use Thread::Queue; use DBI; our $N //= 4; sub child { my $Q = shift; while( my $work = $Q->dequeue ) { for my $thing ( @{ $work } ) { ## process data items } } } my $Q = new Thread::Queue; my @kids = map threads->create( \&child, $Q ), 1 .. $N; my $dbh = DBI->connect( ... ); my $sth->prepare( ...SQL HERE... ); while( my $ref = sth->fetch_* ) { $Q->enqueue( share_clone( $ref ) ); } ### Assume exiting the loop above means no more data $dbh->disconnect; ## tell the kids to die $Q->enqueue( ( undef ) x $N ); ## And wait for kids to clean up $_->join for @kids;;

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".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: MultiThreaded Program in perl
by dtate (Initiate) on Nov 10, 2010 at 14:28 UTC
    Wow, I wish I would of found this thread before I hacked around with Parallel fork manager, Thanks for this Example
Re^2: MultiThreaded Program in perl
by Anonymous Monk on Nov 16, 2010 at 22:21 UTC
    I am getting the following error when I tried to throw an error from my child thread.

    Error: Reached EOF after 0 bytes, header is minimum 4 bytes
    Operation """": no method found, argument in overloaded package main at /home/jpotter/

    Any Idea what the above error is?
      Any Idea what the above error is?

      None whatsoever.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://870440]
[marto]: FWIW, people shipping things as perl, which aren't strictly perl can cause confusion (Perl and OpenWrt - where to the communities intersect?)
[marto]: cpanm is lighter on resources than cpan, which is handy when working with consumer grade NAS hardware

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-03-17 13:15 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (224 votes). Check out past polls.