This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move sub attributes before the signature
[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';
88faa3e1 7 require './test.pl';
624c42e2 8 set_up_inc( qw(../lib) );
1b2ebdae
FC
9 skip_all_if_miniperl(
10 "no dynamic loading on miniperl, no threads/attributes"
11 );
4d76a344
RGS
12}
13
14use strict;
15use Config;
16
624c42e2 17{
77ba2250 18 skip_all_without_config(qw(useithreads d_getppid));
6765206c 19 eval 'use threads; use threads::shared';
3fc97137
RGS
20 plan tests => 3;
21 if ($@) {
22 fail("unable to load thread modules");
23 }
24 else {
25 pass("thread modules loaded");
26 }
4d76a344
RGS
27}
28
4d76a344
RGS
29my ($pid, $ppid) = ($$, getppid());
30my $pid2 : shared = 0;
31my $ppid2 : shared = 0;
32
33new threads( sub { ($pid2, $ppid2) = ($$, getppid()); } ) -> join();
34
d7c042c9
AB
35# If this breaks you're either running under LinuxThreads (and we
36# haven't detected it) or your system doesn't have POSIX thread
37# semantics.
a0a3f718
DH
38# Newer linuxthreads from gnukfreebsd (0.11) does have POSIX thread
39# semantics, so include a version check
40# <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=675606>
bc5c48ae 41my $thread_version = qx[getconf GNU_LIBPTHREAD_VERSION 2>&1] // '';
a0a3f718 42chomp $thread_version;
d7c042c9 43if ($^O =~ /^(?:gnukfreebsd|linux)$/ and
a0a3f718
DH
44 $thread_version =~ /linuxthreads/ and
45 !($thread_version =~ /linuxthreads-(.*)/ && $1 >= 0.11)) {
46 diag "We're running under $^O with linuxthreads <$thread_version>";
d7c042c9
AB
47 isnt($pid, $pid2, "getpid() in a thread is different from the parent on this non-POSIX system");
48 isnt($ppid, $ppid2, "getppid() in a thread is different from the parent on this non-POSIX system");
49} else {
50 is($pid, $pid2, 'getpid() in a thread is the same as in the parent');
51 is($ppid, $ppid2, 'getppid() in a thread is the same as in the parent');
52}