}
} else {
switch(SvTYPE(SHAREDSvGET(shared))) {
+ case SVt_PVAV: {
+ SV* weakref;
+ SV* obj_ref = newSViv(0);
+ SV* obj = newSVrv(obj_ref,"threads::shared::av");
+ AV* hv = newAV();
+ sv_setiv(obj,(IV)shared);
+ weakref = newRV((SV*)hv);
+ sv = newRV_noinc((SV*)hv);
+ sv_rvweaken(weakref);
+ sv_magic((SV*) hv, obj_ref, PERL_MAGIC_tied, Nullch, 0);
+ hv_store(shared_hv, SvPV(id,length), length, weakref, 0);
+ Perl_sharedsv_thrcnt_inc(aTHX_ shared);
+ }
+ break;
+ case SVt_PVHV: {
+ SV* weakref;
+ SV* obj_ref = newSViv(0);
+ SV* obj = newSVrv(obj_ref,"threads::shared::hv");
+ HV* hv = newHV();
+ sv_setiv(obj,(IV)shared);
+ weakref = newRV((SV*)hv);
+ sv = newRV_noinc((SV*)hv);
+ sv_rvweaken(weakref);
+ sv_magic((SV*) hv, obj_ref, PERL_MAGIC_tied, Nullch, 0);
+ hv_store(shared_hv, SvPV(id,length), length, weakref, 0);
+ Perl_sharedsv_thrcnt_inc(aTHX_ shared);
+ }
+ break;
default: {
MAGIC* shared_magic;
SV* value = newSVsv(SHAREDSvGET(shared));
use ExtUtils::testlib;
use strict;
-BEGIN { print "1..7\n" };
+BEGIN { print "1..17\n" };
use threads;
use threads::shared;
ok(1,1,"loaded");
ok(12, $gg == $gg2, "Check we get the same reference ($gg == $gg2)");
ok(13, $$gg eq $$gg2, "And check the values are the same");
ok(14, keys %foo == 0, "And make sure we realy have deleted the values");
-
+{
+ my (%hash1, %hash2);
+ share(%hash1);
+ share(%hash2);
+ $hash1{hash} = \%hash2;
+ $hash2{"bar"} = "foo";
+ ok(15, $hash1{hash}->{bar} eq "foo", "Check hash references work");
+ threads->create(sub { $hash2{"bar2"} = "foo2"})->join();
+ ok(16, $hash1{hash}->{bar2} eq "foo2", "Check hash references work");
+ threads->create(sub { my (%hash3); share(%hash3); $hash2{hash} = \%hash3; $hash3{"thread"} = "yes"})->join();
+ ok(17, $hash1{hash}->{hash}->{thread} eq "yes", "Check hash created in another thread");
+}