Eliminate most of the UTF-8 black smoke by skipping optree tests when
[p5sagit/p5-mst-13.2.git] / ext / threads / t / libc.t
CommitLineData
0f1612a7 1use strict;
2use warnings;
83007387 3
4BEGIN {
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
16use ExtUtils::testlib;
0f1612a7 17
f2cba68d 18sub 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
fc04eb16 32BEGIN {
33 $| = 1;
34 print("1..12\n"); ### Number of tests that will be run ###
35};
83007387 36
37use threads;
38use threads::shared;
f2cba68d 39ok(1, 1, 'Loaded');
40
fc04eb16 41### Start of Testing ###
42
83007387 43my $i = 10;
44my $y = 20000;
fc04eb16 45
83007387 46my %localtime;
fc04eb16 47for (0..$i) {
48 $localtime{$_} = localtime($_);
83007387 49};
fc04eb16 50
f2cba68d 51my $mutex = 2;
83007387 52share($mutex);
fc04eb16 53
83007387 54sub localtime_r {
fc04eb16 55 lock($mutex);
56 my $retval = localtime(shift());
57 return $retval;
83007387 58}
fc04eb16 59
83007387 60my @threads;
fc04eb16 61for (0..$i) {
62 my $thread = threads->create(sub {
63 my $arg = $_;
64 my $localtime = $localtime{$arg};
65 my $error = 0;
66 for (0..$y) {
67 my $lt = localtime($arg);
68 if($localtime ne $lt) {
69 $error++;
70 }
71 }
72 lock($mutex);
73 ok($mutex, ! $error, 'localtime safe');
74 $mutex++;
75 });
76 push @threads, $thread;
83007387 77}
78
fc04eb16 79for (@threads) {
80 $_->join();
83007387 81}
82
fc04eb16 83# EOF