Um, guessing is not allowed :D
#!/usr/bin/perl --
use strict;
use warnings;
use threads;
use threads::shared;
Main(@ARGV);
exit(0);
sub Main {
local $SIG{'HUP'} = 'switchFlag';
share($::flag);
$::flag = !!undef; # false
my $thr = threads->new( \&printer );
$thr->detach();
sleep 10000;
print threads->tid, " is here\n";
} ## end sub Main
sub printer {
while (1) {
sleep 1;
print threads->tid, " Shared: $::flag\n";
}
} ## end sub printer
sub switchFlag {
$::flag = !$::flag;
print threads->tid, " caught signal\n";
$SIG{'HUP'} = 'switchFlag';
}
|