3 # Tests if $$ and getppid return consistent values across threads
8 set_up_inc( qw(../lib) );
10 "no dynamic loading on miniperl, no threads/attributes"
18 skip_all_without_config(qw(useithreads d_getppid));
19 eval 'use threads; use threads::shared';
22 fail("unable to load thread modules");
25 pass("thread modules loaded");
29 my ($pid, $ppid) = ($$, getppid());
30 my $pid2 : shared = 0;
31 my $ppid2 : shared = 0;
33 new threads( sub { ($pid2, $ppid2) = ($$, getppid()); } ) -> join();
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
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>
41 my $thread_version = qx[getconf GNU_LIBPTHREAD_VERSION 2>&1] // '';
42 chomp $thread_version;
43 if ($^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");
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');