On torsdag, dec 19, 2002, at 10:51 Europe/Stockholm, Aravind Srivaths wrote:
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.
Huh, magic is already used to do the locking, but magic is only called before the variable is got or after it has been set, not before it's read and then after.
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.
No they don't, on some systems each thread gets it's own malloc area. (win32 for example).
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); }
SVs live in arenas, arenas are per interpreter.
It should be if it is a shared value.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);
If you feel you can abuse the magic even more I would glad to see it done,
I am not saying it is impossible, just that it is a lot of hard work.
Personally I feel that energy should be used to replace the entire magic system
with parrot style PMCs.
Arthur