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
2010-07-31 17:05:22
What's the other one?
daxim
2010-07-31 18:28:04
+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
2010-07-31 18:43:55
I actually want threads to do things in parallel and speed up my execution time.
David B
2010-07-31 19:44:17
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
2010-08-01 06:23:22
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
2010-08-01 13:06:40
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
2010-08-03 07:29:41
+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
2010-07-31 19:42:38