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