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

Re: Perl Threads Boss/Worker Example

by arpad.szasz (Monk)
on Apr 24, 2012 at 21:56 UTC ( #966949=note: print w/ replies, xml ) Need Help??


in reply to Perl Threads Boss/Worker Example

It seems You are mixing old-style and deprecated threads model(Thread module) with the new ithreads thread model (threads module). Creating the threads should be done like this:

$thread = threads->create( \&do_stuff, param1, $param2 );

Please also note that indirect object notation like new Class is discouraged in Modern Perl in favor of Class->new.

If You do care about worker threads finishing their jobs You should use join() instead of detach() so You don't need the second while loop. Please see the perlthrtut for a more thorough explanation.

Please give the Perl version and OS You are running this, so the monks here can suggest better alternatives to Your current code.

You can also find valuable information regarding threads programming in Perl from fellow monks BrowserUk, ikegami, zentara.

Looking forward to Your reply!


Comment on Re: Perl Threads Boss/Worker Example
Select or Download Code
Re^2: Perl Threads Boss/Worker Example
by joemaniaci (Sexton) on Apr 24, 2012 at 22:11 UTC

    Windows 7, whatever the latest Strawberry perl is.

    The reason I didn't do join was because I wasn't returning anything and it behaved in a non-parallel manner since I had to wait for the joined thread to return before I could start another thread. Unless I of course did something very wrong. My goal was parallelization and so far so good. I just attempted 450 files with 450 threads trying to tax my work computer. Maybe I can request an SSD at work since I think syscalls for read/write is what is the slowest part of my program now.

    I will however look into the more modern code, see how it behaves

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-18 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (41 votes), past polls