Commit | Line | Data |
7473853a |
1 | use strict; |
13c1b207 |
2 | use warnings; |
81f1a921 |
3 | |
4 | BEGIN { |
7473853a |
5 | if ($ENV{'PERL_CORE'}){ |
6 | chdir 't'; |
7 | unshift @INC, '../lib'; |
8 | } |
9 | use Config; |
10 | if (! $Config{'useithreads'}) { |
6c791b15 |
11 | print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); |
7473853a |
12 | exit(0); |
81f1a921 |
13 | } |
14 | } |
15 | |
7473853a |
16 | use ExtUtils::testlib; |
81f1a921 |
17 | |
18 | sub ok { |
19 | my ($id, $ok, $name) = @_; |
7473853a |
20 | if (! defined($name)) { |
21 | $name = ''; |
22 | } |
81f1a921 |
23 | |
24 | # You have to do it this way or VMS will get confused. |
7473853a |
25 | if ($ok) { |
26 | print("ok $id - $name\n"); |
27 | } else { |
28 | print("not ok $id - $name\n"); |
29 | printf("# Failed test at line %d\n", (caller)[2]); |
30 | } |
81f1a921 |
31 | |
7473853a |
32 | return ($ok); |
81f1a921 |
33 | } |
34 | |
7473853a |
35 | BEGIN { |
36 | $| = 1; |
37 | print("1..101\n"); ### Number of tests that will be run ### |
38 | }; |
81f1a921 |
39 | |
81f1a921 |
40 | use threads; |
41 | use threads::shared; |
7473853a |
42 | ok(1, 1, 'Loaded'); |
43 | |
44 | ### Start of Testing ### |
81f1a921 |
45 | |
46 | my $test_count; |
47 | share($test_count); |
48 | $test_count = 2; |
49 | |
50 | for(1..10) { |
51 | my $foo : shared = "foo"; |
52 | ok($test_count++, $foo eq "foo"); |
53 | threads->create(sub { $foo = "bar" })->join(); |
54 | ok($test_count++, $foo eq "bar"); |
55 | my @foo : shared = ("foo","bar"); |
56 | ok($test_count++, $foo[1] eq "bar"); |
57 | threads->create(sub { ok($test_count++, shift(@foo) eq "foo")})->join(); |
58 | ok($test_count++, $foo[0] eq "bar"); |
59 | my %foo : shared = ( foo => "bar" ); |
60 | ok($test_count++, $foo{foo} eq "bar"); |
61 | threads->create(sub { $foo{bar} = "foo" })->join(); |
62 | ok($test_count++, $foo{bar} eq "foo"); |
7473853a |
63 | |
81f1a921 |
64 | threads->create(sub { $foo{array} = \@foo})->join(); |
65 | threads->create(sub { push @{$foo{array}}, "baz"})->join(); |
66 | ok($test_count++, $foo[-1] eq "baz"); |
67 | } |
7473853a |
68 | |
69 | my $shared :shared = &share({}); |
70 | $$shared{'foo'} = 'bar'; |
71 | |
72 | for(1..10) { |
73 | my $str1 = "$shared"; |
74 | my $str2 = "$shared"; |
75 | ok($test_count++, $str1 eq $str2, 'stringify'); |
76 | $str1 = $$shared{'foo'}; |
77 | $str2 = $$shared{'foo'}; |
78 | ok($test_count++, $str1 eq $str2, 'contents'); |
79 | } |
80 | |
6c791b15 |
81 | exit(0); |
82 | |
7473853a |
83 | # EOF |