Commit | Line | Data |
7473853a |
1 | use strict; |
13c1b207 |
2 | use warnings; |
3 | |
dab065ea |
4 | BEGIN { |
7473853a |
5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; |
7 | unshift @INC, '../lib'; |
8 | } |
9 | use Config; |
10 | if (! $Config{'useithreads'}) { |
11 | print("1..0 # Skip: Perl not compiled with 'useithreads'\n"); |
12 | exit(0); |
dab065ea |
13 | } |
dab065ea |
14 | } |
15 | |
7473853a |
16 | use ExtUtils::testlib; |
dab065ea |
17 | |
18 | sub ok { |
19 | my ($id, $ok, $name) = @_; |
20 | |
21 | # You have to do it this way or VMS will get confused. |
7473853a |
22 | if ($ok) { |
23 | print("ok $id - $name\n"); |
24 | } else { |
25 | print("not ok $id - $name\n"); |
26 | printf("# Failed test at line %d\n", (caller)[2]); |
27 | } |
dab065ea |
28 | |
7473853a |
29 | return ($ok); |
dab065ea |
30 | } |
31 | |
7473853a |
32 | BEGIN { |
33 | $| = 1; |
34 | print("1..6\n"); ### Number of tests that will be run ### |
35 | }; |
36 | |
dab065ea |
37 | our $warnmsg; |
7473853a |
38 | BEGIN { |
39 | $SIG{__WARN__} = sub { $warnmsg = shift; }; |
40 | } |
41 | |
dab065ea |
42 | use threads::shared; |
43 | use threads; |
7473853a |
44 | ok(1, 1, 'Loaded'); |
45 | |
46 | ### Start of Testing ### |
47 | |
48 | ok(2, ($warnmsg =~ /Warning, threads::shared has already been loaded/)?1:0, |
9c4972d9 |
49 | "threads has warned us"); |
7473853a |
50 | |
dab065ea |
51 | my $test = "bar"; |
52 | share($test); |
7473853a |
53 | ok(3, $test eq "bar", "Test disabled share not interfering"); |
54 | |
55 | threads->create(sub { |
56 | ok(4, $test eq "bar", "Test disabled share after thread"); |
dab065ea |
57 | $test = "baz"; |
7473853a |
58 | })->join(); |
9c4972d9 |
59 | # Value should either remain unchanged or be value set by other thread |
7473853a |
60 | ok(5, $test eq "bar" || $test eq 'baz', "Test that value is an expected one"); |
9c4972d9 |
61 | |
7473853a |
62 | ok(6, ! is_shared($test), "Check for sharing"); |
dab065ea |
63 | |
7473853a |
64 | # EOF |