Upgrade to threads-1.42
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / shared_attr.t
CommitLineData
13c1b207 1use warnings;
81f1a921 2
3BEGIN {
4# chdir 't' if -d 't';
5# push @INC ,'../lib';
6 require Config; import Config;
7 unless ($Config{'useithreads'}) {
8 print "1..0 # Skip: no useithreads\n";
9 exit 0;
10 }
11}
12
13
14sub ok {
15 my ($id, $ok, $name) = @_;
16
13c1b207 17 $name = '' unless defined $name;
81f1a921 18 # You have to do it this way or VMS will get confused.
19 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
20
21 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
22
23 return $ok;
24}
25
26
27use ExtUtils::testlib;
28use strict;
29BEGIN { print "1..81\n" };
30use threads;
31use threads::shared;
32ok(1,1,"loaded");
33
34my $test_count;
35share($test_count);
36$test_count = 2;
37
38for(1..10) {
39 my $foo : shared = "foo";
40 ok($test_count++, $foo eq "foo");
41 threads->create(sub { $foo = "bar" })->join();
42 ok($test_count++, $foo eq "bar");
43 my @foo : shared = ("foo","bar");
44 ok($test_count++, $foo[1] eq "bar");
45 threads->create(sub { ok($test_count++, shift(@foo) eq "foo")})->join();
46 ok($test_count++, $foo[0] eq "bar");
47 my %foo : shared = ( foo => "bar" );
48 ok($test_count++, $foo{foo} eq "bar");
49 threads->create(sub { $foo{bar} = "foo" })->join();
50 ok($test_count++, $foo{bar} eq "foo");
51
52 threads->create(sub { $foo{array} = \@foo})->join();
53 threads->create(sub { push @{$foo{array}}, "baz"})->join();
54 ok($test_count++, $foo[-1] eq "baz");
55}