So today’s gist is a simple example of how to do two different things with two separate threads. Threading in Perl is misunderstood and often belittled, but it’s pretty straight-forward. The #1 problem that I think people encounter when threading in Perl is that they are using non-thread-safe code. If you’re using a CPAN module, you need to make sure you evaluate it for thread-safety prior to running it with threads (and if it’s using XS, it likely isn’t).
Anyway, this gist takes a function which crunches a set using a calculation routine. The calculation routine takes three parameters:
- The value so far
- And the next value in the set
From there, the calculation routine performs the appropriate action on the next value in the set – given the prior value and the value of N – and then returns the result.
Here’s the Gist: https://gist.github.com/manchicken/6349415