This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make t/op/regexp.t warnings clean.
[perl5.git] / t / op / getpid.t
CommitLineData
4d76a344
RGS
1#!perl -w
2
3# Tests if $$ and getppid return consistent values across threads
4
5BEGIN {
6 chdir 't' if -d 't';
7 @INC = qw(../lib);
88faa3e1 8 require './test.pl';
4d76a344
RGS
9}
10
11use strict;
12use Config;
13
14BEGIN {
15 if (!$Config{useithreads}) {
16 print "1..0 # Skip: no ithreads\n";
17 exit;
18 }
19 if (!$Config{d_getppid}) {
20 print "1..0 # Skip: no getppid\n";
21 exit;
22 }
6765206c
NC
23 if ($ENV{PERL_CORE_MINITEST}) {
24 print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
25 exit 0;
3fc97137 26 }
6765206c 27 eval 'use threads; use threads::shared';
3fc97137
RGS
28 plan tests => 3;
29 if ($@) {
30 fail("unable to load thread modules");
31 }
32 else {
33 pass("thread modules loaded");
34 }
4d76a344
RGS
35}
36
4d76a344
RGS
37my ($pid, $ppid) = ($$, getppid());
38my $pid2 : shared = 0;
39my $ppid2 : shared = 0;
40
41new threads( sub { ($pid2, $ppid2) = ($$, getppid()); } ) -> join();
42
88faa3e1
MS
43is($pid, $pid2, 'pids');
44is($ppid, $ppid2, 'ppids');