1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use Test2::IPC;
# RT123547 observes that if S:K:T is loaded late after multiple threads
# are actually started, it will crash
BEGIN {
eval { require threads; threads->import; 1 } or
plan skip_all => "threads are not supported";
}
# Start two threads doing the same thing concurrently and hope we get
# to the end
my @threads = map {
threads->create( sub {
my $x;
# We have to late-load the module and then demonstrate that it works
# Because of late loading we couldn't have written normal code here, so
# we'll string-eval it
eval <<'EOPERL'
use Syntax::Keyword::Try;
try {
$x = "a";
die "oops";
}
catch ($e) {
$x .= "b";
}
finally {
$x .= "c";
}
1;
EOPERL
or die "Failed - $@";
return $x;
} );
} 1 .. 2;
is( $_->join, "abc", 'try/catch/finally correct result' ) for @threads;
pass "Did not crash";
done_testing;
|