This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
dist/threads/t/libc.t: Add timer to avoid deadlock
[perl5.git] / dist / threads / t / libc.t
CommitLineData
0f1612a7
JH
1use strict;
2use warnings;
83007387
AB
3
4BEGIN {
2adbc9b6 5 require($ENV{PERL_CORE} ? '../../t/test.pl' : './t/test.pl');
f2cba68d 6
955c272e
JH
7 use Config;
8 if (! $Config{'useithreads'}) {
9 skip_all(q/Perl not compiled with 'useithreads'/);
f2cba68d
JH
10 }
11
f9768112
KW
12 my $time_out_factor = $ENV{PERL_TEST_TIME_OUT_FACTOR} || 1;
13 $time_out_factor = 1 if $time_out_factor < 1;
14
15 # Guard against bugs that result in deadlock
16 watchdog(1 * 60 * $time_out_factor);
17
955c272e 18 plan(11);
f2cba68d
JH
19}
20
955c272e 21use ExtUtils::testlib;
83007387 22
955c272e 23use_ok('threads');
f2cba68d 24
fc04eb16
JH
25### Start of Testing ###
26
83007387
AB
27my $i = 10;
28my $y = 20000;
fc04eb16 29
83007387 30my %localtime;
955c272e 31for (1..$i) {
fc04eb16 32 $localtime{$_} = localtime($_);
83007387 33};
fc04eb16 34
83007387 35my @threads;
955c272e
JH
36for (1..$i) {
37 $threads[$_] = threads->create(sub {
38 my $arg = shift;
39 my $localtime = $localtime{$arg};
40 my $error = 0;
41 for (1..$y) {
42 my $lt = localtime($arg);
43 if ($localtime ne $lt) {
44 $error++;
45 }
fc04eb16 46 }
955c272e
JH
47 return $error;
48 }, $_);
83007387
AB
49}
50
955c272e
JH
51for (1..$i) {
52 is($threads[$_]->join(), 0, 'localtime() thread-safe');
83007387
AB
53}
54
561ee912
JH
55exit(0);
56
fc04eb16 57# EOF