TeamSite 6.1
Linux
I am working on speeding up a slow process that goes through every file in a workarea and fires off an iwregen if it detects the file was generated (via EAs). I can use fork, but wanted to put something a little more elegant in place.
I was trying to implement a simple prime number example using the Thread::Queue library, but unfortunately got this message using iwperl (it works with the local perl install):
./thread.pl line 3:
This Perl hasn't been configured and built properly for the threads module to work. (The 'useithreads' configuration option hasn't been used.)
Having threads support requires all of Perl and all of the XS modules in the Perl installation to be rebuilt, it is not just a question of adding the threads module. (In other words, threaded and non-threaded Perls are binary incompatible.)
If you want to the use the threads module, please contact the people who built your Perl.
Cannot continue, aborting.
BEGIN failed--compilation aborted at /export/apps/intrwvn/iw-home/iw-perl/lib/threads.pm line 28.
Compilation failed in require at ./thread.pl line 3.
BEGIN failed--compilation aborted at ./thread.pl line 3.
The script that I ran was:
#!/apps/intrwvn/iw-home/iw-perl/bin/iwperl
use threads;
use Thread::Queue;
my $stream = new Thread::Queue;
my $kid = new threads(\&check_num, $stream, 2);
for my $i (3 .. 1000) {
$stream->enqueue($i);
}
$stream->enqueue(undef);
$kid->join;
sub check_num {
my ($upstream, $cur_prime) =
@_;
my $kid = undef;
my $downstream = new Thread::Queue;
while (my $num = $upstream->dequeue) {
next unless $num % $cur_prime;
if ($kid) {
$downstream->enqueue($num);
} else {
print "Found prime $num\n";
$kid = new threads(\&check_num, $downstream, $num);
}
}
$downstream->enqueue(undef) if $kid;
$kid->join if $kid;
}
Should I bother trying to rebuild iwperl with threading enabled, or just use fork and a partitioning algorithm?