【发布时间】:2014-06-23 06:03:29
【问题描述】:
我正在编写一个 perl 脚本以在 5 秒后退出线程,如下所示。但我无法从 if 条件打印消息。
脚本的输出是闹钟
当线程超时时如何从父进程打印正确的错误消息。
#!/usr/bin/perl
use strict;
use warnings;
use threads;
my $th = threads->create( \&sub1 );
my $thid = $th->tid();
eval
{
$SIG{'KILL'} = sub
{
if ( $th->is_running() )
{
print "timed out, exiting the thread $thid\n";
$th->exit();
}
};
alarm(5);
$th->join();
};
sub sub1
{
my $i = 0;
while ( $i == 0 )
{
}
}
【问题讨论】:
标签: multithreading perl