> How would you make sure the reference counts are correct without
> locking?
>
Yes, a lock is required per variable, but these locks can be stored
in a separate hash, keyed by variable address and magic can be used
to lock a variable before accessing.
It should be possible for multiple interpreters to hold a reference
to the same variable (contrary to what Elizabeth says) - after all
the variable just resides in a heap and all threads share the data
space.
How is a shared variable associated with the shared context?
And should a shift on a shared array not return a mortal variable
- it seems to me that it allocates a new sv and returns that in
Perl_sharedsv_associate:
/* Now if requested allocate private SV */
if (psv && !sv) {
printf("created new sv\n");
*psv = sv = newSV(0);
}
Called from:
void
SHIFT(shared_sv *shared)
CODE:
dTHXc;
SV* sv;
ENTER_LOCK;
SHARED_CONTEXT;
sv = av_shift((AV*)SHAREDSvPTR(shared));
CALLER_CONTEXT;
ST(0) = Nullsv;
Perl_sharedsv_associate(aTHX_ &ST(0), sv, 0);
LEAVE_LOCK;
XSRETURN(1);