This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[ANNOUNCE] Math::BigInt v1.69
[perl5.git] / ext / threads / shared / t / av_refs.t
CommitLineData
13c1b207
DM
1use warnings;
2
8eea0bff
AB
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;
8eea0bff
AB
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
26use ExtUtils::testlib;
27use strict;
28BEGIN { print "1..11\n" };
29use threads;
30use threads::shared;
31ok(1,1,"loaded");
32
33my $sv;
34share($sv);
35$sv = "hi";
36my @av;
37share(@av);
38push @av, $sv;
39ok(2, $av[0] eq "hi");
40push @av, "foo";
41ok(3, $av[1] eq 'foo');
42my $av = threads->create(sub {
43 my $av;
44 my @av2;
45 share($av);
46 share(@av2);
47 $av = \@av2;
48 push @$av, "bar", \@av;
49 return $av;
50})->join();
51ok(4,$av->[0] eq "bar");
52ok(5,$av->[1]->[0] eq 'hi');
53threads->create(sub { $av[0] = "hihi" })->join();
54ok(6,$av->[1]->[0] eq 'hihi');
55ok(7, pop(@{$av->[1]}) eq "foo");
56ok(8, scalar(@{$av->[1]}) == 1);
57threads->create(sub { @$av = () })->join();
58threads->create(sub { ok(9, scalar @$av == 0)})->join();
59threads->create(sub { unshift(@$av, threads->create(sub { my @array; share(@array); return \@array})->join())})->join();
60ok(10, ref($av->[0]) eq 'ARRAY');
61threads->create(sub { push @{$av->[0]}, \@av })->join();
62threads->create(sub { $av[0] = 'testtest'})->join();
63threads->create(sub { ok(11, $av->[0]->[0]->[0] eq 'testtest')})->join();
64
65
66
67
68
69