小编Sam*_*cci的帖子

Perl线程中断睡眠不起作用

我想理解,因为如果我运行这段代码

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

use threads;
use threads::shared;

sub mythread {
    my $end = 0; # Thread termination variable

    while(!$end) {
        eval {
            local $SIG{'ALRM'} = sub {
                print "SIGALARM received\n";
                $end = 1;
                die "Alarm!\n";
            };

            sleep(5); # Wait
        };
        die $@ unless $@ eq "Alarm!\n";
    }
}

my $end = 0; # Main termination variable
$SIG{'INT'} = sub {
    $end = 1; # Set Main termination variable
};

my $thr = threads->create( \&mythread …
Run Code Online (Sandbox Code Playgroud)

perl multithreading sleep

3
推荐指数
1
解决办法
251
查看次数

标签 统计

multithreading ×1

perl ×1

sleep ×1