As we're not passing over (or copying in) a NUL, don't need that extra
[p5sagit/p5-mst-13.2.git] / ext / threads / t / libc.t
index 2c24bad..740588a 100644 (file)
@@ -6,46 +6,20 @@ BEGIN {
         chdir 't';
         unshift @INC, '../lib';
     }
-    use Config;
-    if (! $Config{'useithreads'}) {
-        print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
-        exit(0);
-    }
-}
 
-use ExtUtils::testlib;
+    require($ENV{PERL_CORE} ? "./test.pl" : "./t/test.pl");
 
-sub ok {
-    my ($id, $ok, $name) = @_;
-
-    # You have to do it this way or VMS will get confused.
-    if ($ok) {
-        print("ok $id - $name\n");
-    } else {
-        print("not ok $id - $name\n");
-        printf("# Failed test at line %d\n", (caller)[2]);
+    use Config;
+    if (! $Config{'useithreads'}) {
+        skip_all(q/Perl not compiled with 'useithreads'/);
     }
 
-    return ($ok);
+    plan(11);
 }
 
-use threads;
-
-BEGIN {
-    eval {
-        require threads::shared;
-        import threads::shared;
-    };
-    if ($@ || ! $threads::shared::threads_shared) {
-        print("1..0 # Skip: threads::shared not available\n");
-        exit(0);
-    }
-
-    $| = 1;
-    print("1..12\n");   ### Number of tests that will be run ###
-};
+use ExtUtils::testlib;
 
-ok(1, 1, 'Loaded');
+use_ok('threads');
 
 ### Start of Testing ###
 
@@ -53,40 +27,28 @@ my $i = 10;
 my $y = 20000;
 
 my %localtime;
-for (0..$i) {
+for (1..$i) {
     $localtime{$_} = localtime($_);
 };
 
-my $mutex = 2;
-share($mutex);
-
-sub localtime_r {
-    lock($mutex);
-    my $retval = localtime(shift());
-    return $retval;
-}
-
 my @threads;
-for (0..$i) {
-    my $thread = threads->create(sub {
-                    my $arg = $_;
-                    my $localtime = $localtime{$arg};
-                    my $error = 0;
-                    for (0..$y) {
-                        my $lt = localtime($arg);
-                        if($localtime ne $lt) {
-                            $error++;
+for (1..$i) {
+    $threads[$_] = threads->create(sub {
+                        my $arg = shift;
+                        my $localtime = $localtime{$arg};
+                        my $error = 0;
+                        for (1..$y) {
+                            my $lt = localtime($arg);
+                            if ($localtime ne $lt) {
+                                $error++;
+                            }
                         }
-                    }
-                    lock($mutex);
-                    ok($mutex, ! $error, 'localtime safe');
-                    $mutex++;
-                  });
-    push @threads, $thread;
+                        return $error;
+                    }, $_);
 }
 
-for (@threads) {
-    $_->join();
+for (1..$i) {
+    is($threads[$_]->join(), 0, 'localtime() thread-safe');
 }
 
 # EOF