threads.pm contains the following statement:
It is also important to note that you must enable threads by
doing C<use threads> as early as possible in the script, and
that it is not possible to enable threading inside an
C<eval "">, C<do>, C<require>, or C<use>.
Thinking about it, I don't believe the latter part of that sentence is true
anymore. For example, the following works just fine on both threaded and
non-threaded Perls:
#!/usr/bin/perl
use strict;
use warnings;
my $i_am_threaded = eval 'use threads; 1';
MAIN:
{
if ($i_am_threaded) {
threads->create(sub {
print("This is a thread speaking.\n");
})->join();
} else {
print("Can't use threads.\n");
}
}
# EOF
While the first part of the statement is definitely good advice, should the
latter part be removed, or can anyone recommend some more appropriate wording?