| Line | |
|---|
| 1 |
|
|---|
| 2 | BEGIN {
|
|---|
| 3 | chdir 't' if -d 't';
|
|---|
| 4 | push @INC, '../lib';
|
|---|
| 5 | require Config; import Config;
|
|---|
| 6 | unless ($Config{'useithreads'}) {
|
|---|
| 7 | print "1..0 # Skip: no useithreads\n";
|
|---|
| 8 | exit 0;
|
|---|
| 9 | }
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | use ExtUtils::testlib;
|
|---|
| 13 | use strict;
|
|---|
| 14 | BEGIN { $| = 1; print "1..11\n"};
|
|---|
| 15 |
|
|---|
| 16 | use threads;
|
|---|
| 17 | use threads::shared;
|
|---|
| 18 | my $i = 10;
|
|---|
| 19 | my $y = 20000;
|
|---|
| 20 | my %localtime;
|
|---|
| 21 | for(0..$i) {
|
|---|
| 22 | $localtime{$_} = localtime($_);
|
|---|
| 23 | };
|
|---|
| 24 | my $mutex = 1;
|
|---|
| 25 | share($mutex);
|
|---|
| 26 | sub 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 | }
|
|---|
| 34 | my @threads;
|
|---|
| 35 | for(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 |
|
|---|
| 57 | for(@threads) {
|
|---|
| 58 | $_->join();
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.