6 require Config; import Config;
7 unless ($Config{'useithreads'}) {
8 print "1..0 # Skip: no useithreads\n";
15 my ($id, $ok, $name) = @_;
17 $name = '' unless defined $name;
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";
21 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
27 my ($id, $ok, $name) = @_;
28 print "ok $id # skip _thrcnt - $name \n";
31 use ExtUtils::testlib;
33 BEGIN { print "1..13\n" };
35 use threads::shared qw(:DEFAULT _refcnt _id);
42 ok(2, !defined ${$foo{foo}}, "Check deref");
44 ok(3, ${$foo{foo}} eq "test", "Check deref after assign");
45 threads->create(sub{${$foo{foo}} = "test2";})->join();
46 ok(4, $foo eq "test2", "Check after assign in another thread");
47 my $bar = delete($foo{foo});
48 ok(5, $$bar eq "test2", "check delete");
49 threads->create( sub {
55 ok(6, ${$foo{test}} eq "thread3", "Check reference created in another thread");
58 ok(7, ${$foo{test}} eq "test", "Check reference");
59 my $gg2 = delete($foo{test});
60 ok(8, _id($$gg) == _id($$gg2),
61 sprintf("Check we get the same thing (%x vs %x)",
62 _id($$gg),_id($$gg2)));
63 ok(9, $$gg eq $$gg2, "And check the values are the same");
64 ok(10, keys %foo == 0, "And make sure we realy have deleted the values");
69 $hash1{hash} = \%hash2;
70 $hash2{"bar"} = "foo";
71 ok(11, $hash1{hash}->{bar} eq "foo", "Check hash references work");
72 threads->create(sub { $hash2{"bar2"} = "foo2"})->join();
73 ok(12, $hash1{hash}->{bar2} eq "foo2", "Check hash references work");
74 threads->create(sub { my (%hash3); share(%hash3); $hash2{hash} = \%hash3; $hash3{"thread"} = "yes"})->join();
75 ok(13, $hash1{hash}->{hash}->{thread} eq "yes", "Check hash created in another thread");