This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
4f6f6ed3ae192be8c1ede194c4230448d174081a
[perl5.git] / ext / threads / t / libc.t
1 use strict;
2 use warnings;
3
4 BEGIN {
5     require($ENV{PERL_CORE} ? '../../t/test.pl' : './t/test.pl');
6
7     use Config;
8     if (! $Config{'useithreads'}) {
9         skip_all(q/Perl not compiled with 'useithreads'/);
10     }
11
12     plan(11);
13 }
14
15 use ExtUtils::testlib;
16
17 use_ok('threads');
18
19 ### Start of Testing ###
20
21 my $i = 10;
22 my $y = 20000;
23
24 my %localtime;
25 for (1..$i) {
26     $localtime{$_} = localtime($_);
27 };
28
29 my @threads;
30 for (1..$i) {
31     $threads[$_] = threads->create(sub {
32                         my $arg = shift;
33                         my $localtime = $localtime{$arg};
34                         my $error = 0;
35                         for (1..$y) {
36                             my $lt = localtime($arg);
37                             if ($localtime ne $lt) {
38                                 $error++;
39                             }
40                         }
41                         return $error;
42                     }, $_);
43 }
44
45 for (1..$i) {
46     is($threads[$_]->join(), 0, 'localtime() thread-safe');
47 }
48
49 exit(0);
50
51 # EOF