1#!perl -w 2 3# Tests if $$ and getppid return consistent values across threads 4 5BEGIN { 6 chdir 't' if -d 't'; 7 require './test.pl'; 8 set_up_inc( qw(../lib) ); 9 skip_all_if_miniperl( 10 "no dynamic loading on miniperl, no threads/attributes" 11 ); 12} 13 14use strict; 15use Config; 16 17{ 18 skip_all_without_config(qw(useithreads d_getppid)); 19 eval 'use threads; use threads::shared'; 20 plan tests => 3; 21 if ($@) { 22 fail("unable to load thread modules"); 23 } 24 else { 25 pass("thread modules loaded"); 26 } 27} 28 29my ($pid, $ppid) = ($$, getppid()); 30my $pid2 : shared = 0; 31my $ppid2 : shared = 0; 32 33new threads( sub { ($pid2, $ppid2) = ($$, getppid()); } ) -> join(); 34 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. 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> 41my $thread_version = qx[getconf GNU_LIBPTHREAD_VERSION 2>&1] // ''; 42chomp $thread_version; 43if ($^O =~ /^(?:gnukfreebsd|linux)$/ and 44 $thread_version =~ /linuxthreads/ and 45 !($thread_version =~ /linuxthreads-(.*)/ && $1 >= 0.11)) { 46 diag "We're running under $^O with linuxthreads <$thread_version>"; 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} 53