P
Prince Al
Hi,
I am trying to write some code that creates threads to run data load
jobs. There is also an extra thread created that watches for a
specific file to be created. When this file is found, the watcher
thread sends stop signals to all currently running threads. My code
appears to exit correctly, but I cannot seem to get the subroutine of
the SIG command to exit correctly.
We are running HP-UX and the version of Perl we have is 5.8.8 (with
thread support obviously). A cut down version of my code is below.
Thanks in advance for any help
Cheers
Tim
#!/opt/perl_5.8.8cu/bin/perl
use strict;
use warnings;
use threads;
my $system = "test";
my $hard_stop_file = "/tmp/$system"."_hard.stop";
if (-f $hard_stop_file) {
unlink($hard_stop_file);
}
my $watcher_thread = threads->new(\&hard_stop_watcher);
$watcher_thread->detach();
foreach my $i (0..4) {
threads->new(\&flock_test, $i);
}
while (scalar(threads->list()) > 0) {
sleep 1;
}
sub flock_test {
$SIG{'STOP'} = sub {
print "I cannot get this to print!\n";
threads->exit();
};
sleep 20;
}
sub hard_stop_watcher {
while ( !-f $hard_stop_file) {
sleep 1;
}
print "$hard_stop_file found...\n";
foreach my $thr (threads->list) {
print "killing $thr\n";
$thr->kill('STOP')->detach();
}
threads->exit();
}
I am trying to write some code that creates threads to run data load
jobs. There is also an extra thread created that watches for a
specific file to be created. When this file is found, the watcher
thread sends stop signals to all currently running threads. My code
appears to exit correctly, but I cannot seem to get the subroutine of
the SIG command to exit correctly.
We are running HP-UX and the version of Perl we have is 5.8.8 (with
thread support obviously). A cut down version of my code is below.
Thanks in advance for any help
Cheers
Tim
#!/opt/perl_5.8.8cu/bin/perl
use strict;
use warnings;
use threads;
my $system = "test";
my $hard_stop_file = "/tmp/$system"."_hard.stop";
if (-f $hard_stop_file) {
unlink($hard_stop_file);
}
my $watcher_thread = threads->new(\&hard_stop_watcher);
$watcher_thread->detach();
foreach my $i (0..4) {
threads->new(\&flock_test, $i);
}
while (scalar(threads->list()) > 0) {
sleep 1;
}
sub flock_test {
$SIG{'STOP'} = sub {
print "I cannot get this to print!\n";
threads->exit();
};
sleep 20;
}
sub hard_stop_watcher {
while ( !-f $hard_stop_file) {
sleep 1;
}
print "$hard_stop_file found...\n";
foreach my $thr (threads->list) {
print "killing $thr\n";
$thr->kill('STOP')->detach();
}
threads->exit();
}