我试图让这两个子例程同时运行。当我启动程序时,我最终得到:
Perl exited with active threads:
2 running and unjoined
0 finished and unjoined
0 running and detached
没有任何东西可以打印到控制台上。我预计 while(1) 将保持活跃直到 SIGTERM。
线
use threads;
my $t1 = threads->create( \&sub2 );
my $t2 = threads->create( \&sub1 );
sub sub2 {
my $dbh = get_connector();
while (1) {
print "Worker 2 Running";
sleep 2;
}
}
sub sub1 {
while (1) {
print "Worker 1 Running";
sleep 1;
}
}
你能发现这里的缺陷吗!