| 1 |
# |
| 2 |
# make sure many threads all get same default paths. |
| 3 |
# |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use version 0.77; |
| 7 |
use Config; |
| 8 |
|
| 9 |
BEGIN { |
| 10 |
unless ($Config{useithreads}) { |
| 11 |
print "1..0 # SKIP no ithreads\n"; |
| 12 |
exit 0; |
| 13 |
} |
| 14 |
my $v = version->parse($Config{version}); |
| 15 |
if ($v >= '5.9.5' and $v < '5.10.1') { |
| 16 |
# |
| 17 |
# In perl-5.10.0, Perl_parser_dup() was called with a null pointer |
| 18 |
# to indicate (presumably) that there was no parser to dup. The |
| 19 |
# first thing it did was to check for the null then return null. |
| 20 |
# However, Perl_parser_dup was prototyped with a nonnull attribute |
| 21 |
# applied to both its' args, causing the null check to later be |
| 22 |
# optimized away with -O2 on gcc-like compilers. |
| 23 |
# |
| 24 |
# Perl_parser_dup along with the null test and the nonnull |
| 25 |
# attributes were introduced in perl-5.9.5. |
| 26 |
# |
| 27 |
# The nonnull attribute for parser arg was removed in |
| 28 |
# perl-5.10.1-RC1. |
| 29 |
# |
| 30 |
print "1..0 # SKIP threads broken in Perl_parser_dup\n"; |
| 31 |
exit 0; |
| 32 |
} |
| 33 |
if ($Config{osname} eq 'openbsd' and $Config{osvers} eq '7.0') { |
| 34 |
print "1..0 # SKIP OpenBSD 7.0 threads broken?\n"; |
| 35 |
exit 0; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
use threads; |
| 40 |
use threads::shared; |
| 41 |
use MyTest; |
| 42 |
use Try::Tiny; |
| 43 |
|
| 44 |
use vars qw(@OPTS); |
| 45 |
|
| 46 |
BEGIN { |
| 47 |
@OPTS = qw(:persist=foo); |
| 48 |
ok 1, 'began'; |
| 49 |
} |
| 50 |
|
| 51 |
use UUID @OPTS; |
| 52 |
|
| 53 |
ok 1, 'loaded'; |
| 54 |
|
| 55 |
my $cnt = 0; |
| 56 |
share($cnt); |
| 57 |
|
| 58 |
sub t (&) { |
| 59 |
my $t = shift; |
| 60 |
my ($rv, $err); |
| 61 |
$rv = try { $t->() } catch { $err = $_; undef }; |
| 62 |
return $rv, $err; |
| 63 |
} |
| 64 |
|
| 65 |
sub doit { |
| 66 |
note 'in doit()'; |
| 67 |
my $c; { lock $cnt; $c = ++$cnt } |
| 68 |
note "c: $c"; |
| 69 |
my ($rv,$er) = t{ UUID::_persist() }; |
| 70 |
is $rv, 'foo', "path seems correct $cnt"; |
| 71 |
is $er, undef, "path correct $cnt"; |
| 72 |
} |
| 73 |
|
| 74 |
note 'spawn 1'; my $thr1 = threads->create(\&doit); $thr1->join; |
| 75 |
note 'spawn 2'; my $thr2 = threads->create(\&doit); $thr2->join; |
| 76 |
note 'spawn 3'; my $thr3 = threads->create(\&doit); $thr3->join; |
| 77 |
|
| 78 |
note 'spawn 4'; my $thr4 = threads->create(\&doit); |
| 79 |
note 'spawn 5'; my $thr5 = threads->create(\&doit); |
| 80 |
note 'spawn 6'; my $thr6 = threads->create(\&doit); |
| 81 |
$thr4->join; |
| 82 |
$thr6->join; |
| 83 |
$thr5->join; |
| 84 |
|
| 85 |
done_testing; |