develooper Front page | perl.perl5.porters | Postings from July 2011

Re: lock() on a code ref?

Thread Previous | Thread Next
Reini Urban
July 25, 2011 22:36
Re: lock() on a code ref?
Message ID:
This came up recently in a new thread, citing an old p5p summary.
Great old days!

2009/1/21 Jerry D. Hedden <>:
> Jerry D. Hedden wrote:
>> The following comes from pp.c:
>> PP(pp_lock)
>> {
>>     dVAR;
>>     dSP;
>>     dTOPss;
>>     SV *retsv = sv;
>>     SvLOCK(sv);
>>     if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV
>>       || SvTYPE(retsv) == SVt_PVCV) {
>>       retsv = refto(retsv);
>>     }
>>     SETs(retsv);
>>     RETURN;
>> }
>> Why is there a check for a code ref in the 'if' statement?
>> SvTYPE(retsv) == SVt_PVCV
>> This 'if' was added with change 170.  Was it just notional?
>> Since you can't lock code refs, I think this check should be removed.
>> Right?
> Dave Mitchell wrote:
>> Well, I think the code is more along the lines of
>>    'return a scalar value.  If the thing being locked isn't a scalar,
>>    return a reference to it instead.'
>> So I think its safest to leave it as-is. (Who knows, one day coderefs might
>> locakable!).
>> Unless there's any pressing reason to remove it?
> Other than the fact that it's superfluous code that is executed
> needlessly everytime the lock() function is called.  And since
> code locks aren't something that is even remotely being speculated
> upon, I'm going to submit a patch to remove this.

Why cannot you think of locking a coderef?
subs can be changed in threads via B::Generate
(if one particular assert is being removed), and should not so if locked.
I cannot think of any case why it should be disallowed generally.

BTW: packages should also be lock'able to be able to optimize method lookup.
I'm just not sure the syntax how to "final" packages, to promise the
compiler optimizer
that they are not changed at run-time. "changed" meaning no @ISA
changes and no run-time subs/methods being added or removed.
Reini Urban

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About