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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#!perl
use strict;
use warnings;
require './test.pl';
skip_all_without_config('useithreads');
skip_all_if_miniperl("no dynamic loading on miniperl, no threads");
plan(3);
require threads;
{
fresh_perl_is('
use threads;
use strict;
use warnings;
sub main::IsA {
use feature "state";
state $upper_char = ord "A";
state $lower_char = ord "a";
return sprintf "%x", $lower_char++ if shift;
return sprintf "%x", $upper_char++;
}
my @threads = map +threads->create(sub {
sleep 0.1;
for (1..2500) {
return 0 unless eval "qq(A) =~ qr/\\\p{main::IsA}/";
return 0 unless eval "qq(a) =~ qr/\\\p{main::IsA}/i";
}
return 1;
}), (0..1);
my $success = $threads[0]->join;
$success += $threads[1]->join;
print $success;',
2,
{},
"Simultaneous threads worked");
}
{
fresh_perl_is('
use threads;
use strict;
use warnings;
sub InLongSleep {
use feature "state";
state $which = 0;
sleep(60) unless $which++;
return "0042";
}
sub InQuick {
return sprintf "%x", ord("C");
}
my $thread0 = threads->create(sub {
my $a = \'\p{InLongSleep}\';
qr/$a/;
return 1;
});
my $thread1 = threads->create(sub {
sleep 1;
my $c = \'\p{InQuick}\';
return "C" =~ /$c/;
});
print $thread1->join;
$thread0->detach();',
1,
{},
"One thread hung on a defn doesn't impinge on other's other defns");
}
{
fresh_perl_like('
use threads;
use strict;
use warnings;
sub InLongSleep {
use feature "state";
state $which = 0;
sleep(25) unless $which++;
return "0042";
}
my @threads = map +threads->create(sub {
sleep 1;
my $a = \'\p{InLongSleep}\';
qr/$a/;
return 1;
}), (0..1);
$threads[1]->join;
$threads[0]->detach();',
qr/Thread \d+ terminated abnormally: Timeout waiting for another thread to define "InLongSleep" in regex/,
{},
"One thread hung on a definition doesn't delay another indefinitely");
}
1;
|