Commit | Line | Data |
---|---|---|
0f1612a7 | 1 | use strict; |
2 | use warnings; | |
83007387 | 3 | |
4 | BEGIN { | |
0f1612a7 | 5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; | |
7 | unshift @INC, '../lib'; | |
8 | } | |
9 | use Config; | |
fc04eb16 | 10 | if (! $Config{'useithreads'}) { |
11 | print("1..0 # Skip: Perl not compiled with 'useithreads'\n"); | |
12 | exit(0); | |
83007387 | 13 | } |
14 | } | |
15 | ||
16 | use ExtUtils::testlib; | |
0f1612a7 | 17 | |
f2cba68d | 18 | sub ok { |
19 | my ($id, $ok, $name) = @_; | |
20 | ||
21 | # You have to do it this way or VMS will get confused. | |
22 | if ($ok) { | |
23 | print("ok $id - $name\n"); | |
24 | } else { | |
25 | print("not ok $id - $name\n"); | |
26 | printf("# Failed test at line %d\n", (caller)[2]); | |
27 | } | |
28 | ||
29 | return ($ok); | |
30 | } | |
31 | ||
58a3a76c | 32 | use threads; |
33 | ||
fc04eb16 | 34 | BEGIN { |
58a3a76c | 35 | eval { |
36 | require threads::shared; | |
37 | import threads::shared; | |
38 | }; | |
39 | if ($@ || ! $threads::shared::threads_shared) { | |
40 | print("1..0 # Skip: threads::shared not available\n"); | |
41 | exit(0); | |
42 | } | |
43 | ||
fc04eb16 | 44 | $| = 1; |
45 | print("1..12\n"); ### Number of tests that will be run ### | |
46 | }; | |
83007387 | 47 | |
f2cba68d | 48 | ok(1, 1, 'Loaded'); |
49 | ||
fc04eb16 | 50 | ### Start of Testing ### |
51 | ||
83007387 | 52 | my $i = 10; |
53 | my $y = 20000; | |
fc04eb16 | 54 | |
83007387 | 55 | my %localtime; |
fc04eb16 | 56 | for (0..$i) { |
57 | $localtime{$_} = localtime($_); | |
83007387 | 58 | }; |
fc04eb16 | 59 | |
f2cba68d | 60 | my $mutex = 2; |
83007387 | 61 | share($mutex); |
fc04eb16 | 62 | |
83007387 | 63 | sub localtime_r { |
fc04eb16 | 64 | lock($mutex); |
65 | my $retval = localtime(shift()); | |
66 | return $retval; | |
83007387 | 67 | } |
fc04eb16 | 68 | |
83007387 | 69 | my @threads; |
fc04eb16 | 70 | for (0..$i) { |
71 | my $thread = threads->create(sub { | |
72 | my $arg = $_; | |
73 | my $localtime = $localtime{$arg}; | |
74 | my $error = 0; | |
75 | for (0..$y) { | |
76 | my $lt = localtime($arg); | |
77 | if($localtime ne $lt) { | |
78 | $error++; | |
79 | } | |
80 | } | |
81 | lock($mutex); | |
82 | ok($mutex, ! $error, 'localtime safe'); | |
83 | $mutex++; | |
84 | }); | |
85 | push @threads, $thread; | |
83007387 | 86 | } |
87 | ||
fc04eb16 | 88 | for (@threads) { |
89 | $_->join(); | |
83007387 | 90 | } |
91 | ||
fc04eb16 | 92 | # EOF |