views:

112

answers:

3

I'm new to multithreading in Perl and looking for something similar to Java's thread pools. Any recommendations?

A: 

Well CPAN, which contains all things perl(ish) has a thread pool implementation, Thread::Pool. There is another implementation, but it's currently not production code.

scope_creep
What's the other one?
daxim
+2  A: 

If you really want threads, then look at threads.pm and threads::shared.

However -- Perl doesn't have lightweight threads like Java and few people (relatively) use them. Many "thread problems" can be solved (often better, too) with event based programming.

Look for AnyEvent for that: http://search.cpan.org/search?query=anyevent&mode=all

Ask Bjørn Hansen
I actually want threads to do things in parallel and speed up my execution time.
David B
Unless you have long-running worker threads and little need for exchange of data between threads, you are probably better off forking if your goal is parallelization.
ysth
can you explain the differences? I want to perform a couple of tasks in prarllel (they do not depend on each other) than wait for them to finish and continue.
David B
Hi David -What are the "couple of tasks"?If you have something CPU intensive, then the general advice would be to fork and just do the work in multiple processes. "forking" is basically the unix way of parallel execution.If you have something that's not CPU intensive, but has many connections open (for example), then the generic advice is to use an event loop (see AnyEvent.pm).
Ask Bjørn Hansen
+1  A: 

use threads; use threads::shared;

You can also take a look at subs::parallel module if you're interested in more transparent implementation.

hlynur
subs:parallel seems nice!
David B