This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #24940] "sub foo :unique" segfaults
[perl5.git] / ext / threads / t / libc.t
CommitLineData
83007387
AB
1
2BEGIN {
3 chdir 't' if -d 't';
974ec8aa 4 push @INC, '../lib';
83007387
AB
5 require Config; import Config;
6 unless ($Config{'useithreads'}) {
7 print "1..0 # Skip: no useithreads\n";
8 exit 0;
9 }
10}
11
12use ExtUtils::testlib;
13use strict;
14BEGIN { $| = 1; print "1..11\n"};
15
16use threads;
17use threads::shared;
18my $i = 10;
19my $y = 20000;
20my %localtime;
21for(0..$i) {
22 $localtime{$_} = localtime($_);
23};
24my $mutex = 1;
25share($mutex);
26sub localtime_r {
27# print "Waiting for lock\n";
28 lock($mutex);
29# print "foo\n";
30 my $retval = localtime(shift());
31# unlock($mutex);
32 return $retval;
33}
34my @threads;
35for(0..$i) {
36 my $thread = threads->create(sub {
37 my $arg = $_;
38 my $localtime = $localtime{$arg};
39 my $error = 0;
40 for(0..$y) {
41 my $lt = localtime($arg);
42 if($localtime ne $lt) {
43 $error++;
44 }
45 }
46 lock($mutex);
47 if($error) {
48 print "not ok $mutex # not a safe localtime\n";
49 } else {
50 print "ok $mutex\n";
51 }
52 $mutex++;
53 });
54 push @threads, $thread;
55}
56
57for(@threads) {
58 $_->join();
59}
60