Perl updating variables in forks

NOTE: this tutorial describes the new Perl threading flavour introduced in Perl 5.6.0 called interpreter threads, or ithreads for short.

perl updating variables in forks-60perl updating variables in forks-85

A module could possibly be rewritten to utilize the new features in threaded Perl to increase performance in a threaded environment.

If you're using a module that's not thread-safe for some reason, you can protect yourself by using it from one, and only one thread at all. The core the threads manpage module provides the basic functions you need to write threaded programs.

Once the event has been passed on, the boss thread goes back to waiting for another event. While tasks aren't necessarily performed faster than with any other method, it tends to have the best user-response times.

In the work crew model, several threads are created that do essentially the same thing to different pieces of data.

They aren't POSIX threads, or Dec Threads, or Java's Green threads, or Win32 threads.

There are similarities, and the broad concepts are the same, but if you start looking for implementation details you're going to be either disappointed or confused. This is not to say that Perl threads are completely different from everything that's ever come before--they're not.

So if your system blocks the entire process on sleep(), Perl usually will as well. The addition of threads has changed Perl's internals substantially.

There are implications for people who write modules with XS code or external libraries.

However, since perl data is not shared among threads by default, Perl modules stand a high chance of being thread-safe or can be made thread-safe easily.

Tags: , ,