Support for references in shared arrays.
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / hv_refs.t
CommitLineData
0dc5f2bb 1BEGIN {
2# chdir 't' if -d 't';
3# push @INC ,'../lib';
4 require Config; import Config;
5 unless ($Config{'useithreads'}) {
6 print "1..0 # Skip: no useithreads\n";
7 exit 0;
8 }
9}
10
11
12sub ok {
13 my ($id, $ok, $name) = @_;
14
15 # You have to do it this way or VMS will get confused.
16 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
17
18 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
19
20 return $ok;
21}
22
23
24
25use ExtUtils::testlib;
26use strict;
27BEGIN { print "1..7\n" };
28use threads;
29use threads::shared;
30ok(1,1,"loaded");
31my $foo;
32share($foo);
33my %foo;
34share(%foo);
35$foo{"foo"} = \$foo;
36ok(2, ${$foo{foo}} == undef, "Check deref");
37$foo = "test";
38ok(3, ${$foo{foo}} eq "test", "Check deref after assign");
39threads->create(sub{${$foo{foo}} = "test2";})->join();
40ok(4, $foo eq "test2", "Check after assign in another thread");
41ok(5, threads::shared::_thrcnt($foo) == 2, "Check refcount");
42my $bar = delete($foo{foo});
43ok(6, $$bar eq "test2", "check delete");
44ok(7, threads::shared::_thrcnt($foo) == 1, "Check refcount after delete");