xref: /openbsd-src/gnu/usr.bin/perl/dist/threads/t/libc.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1b39c5158Smillertuse strict;
2b39c5158Smillertuse warnings;
3b39c5158Smillert
4b39c5158SmillertBEGIN {
5b39c5158Smillert    require($ENV{PERL_CORE} ? '../../t/test.pl' : './t/test.pl');
6b39c5158Smillert
7b39c5158Smillert    use Config;
8b39c5158Smillert    if (! $Config{'useithreads'}) {
9b39c5158Smillert        skip_all(q/Perl not compiled with 'useithreads'/);
10b39c5158Smillert    }
11b39c5158Smillert
12256a93a4Safresh1    # Guard against bugs that result in deadlock
13*f2a19305Safresh1    watchdog(1 * 60);
14256a93a4Safresh1
15b39c5158Smillert    plan(11);
16b39c5158Smillert}
17b39c5158Smillert
18b39c5158Smillertuse ExtUtils::testlib;
19b39c5158Smillert
20b39c5158Smillertuse_ok('threads');
21b39c5158Smillert
22b39c5158Smillert### Start of Testing ###
23b39c5158Smillert
24b39c5158Smillertmy $i = 10;
25b39c5158Smillertmy $y = 20000;
26b39c5158Smillert
27b39c5158Smillertmy %localtime;
28b39c5158Smillertfor (1..$i) {
29b39c5158Smillert    $localtime{$_} = localtime($_);
30b39c5158Smillert};
31b39c5158Smillert
32b39c5158Smillertmy @threads;
33b39c5158Smillertfor (1..$i) {
34b39c5158Smillert    $threads[$_] = threads->create(sub {
35b39c5158Smillert                        my $arg = shift;
36b39c5158Smillert                        my $localtime = $localtime{$arg};
37b39c5158Smillert                        my $error = 0;
38b39c5158Smillert                        for (1..$y) {
39b39c5158Smillert                            my $lt = localtime($arg);
40b39c5158Smillert                            if ($localtime ne $lt) {
41b39c5158Smillert                                $error++;
42b39c5158Smillert                            }
43b39c5158Smillert                        }
44b39c5158Smillert                        return $error;
45b39c5158Smillert                    }, $_);
46b39c5158Smillert}
47b39c5158Smillert
48b39c5158Smillertfor (1..$i) {
49b39c5158Smillert    is($threads[$_]->join(), 0, 'localtime() thread-safe');
50b39c5158Smillert}
51b39c5158Smillert
52b39c5158Smillertexit(0);
53b39c5158Smillert
54b39c5158Smillert# EOF
55