develooper Front page | perl.perl5.porters | Postings from April 2006

Re: how should %^H work with lexical pramas

Thread Previous | Thread Next
Nicholas Clark
April 1, 2006 02:49
Re: how should %^H work with lexical pramas
Message ID:
On Fri, Mar 31, 2006 at 10:11:44PM +0100, Nicholas Clark wrote:
> On Fri, Mar 31, 2006 at 06:45:54PM +0100, Nicholas Clark wrote:
> > Is PL_compiling.cop_hints shared across threads?
> > +    PL_compiling.cop_hints = PL_curcop->cop_hints;
> > +    /* FIXME - is this threadsafe?  Or is it manipulating a shared
> > +       resource?  */
> > +    if (PL_compiling.cop_hints) {
> > +       PL_compiling.cop_hints->refcounted_he_refcnt++;
> Oops. I didn't phrase my question correctly. Is  PL_compiling.cop_hints
> shared across threads because it's a copy of PL_curcop->cop_hints and
> PL_curcop is pointing into a data structure that is shared between threads?
> (And therefore that ++ is a race condition)

Yes, it is:

[Program is
./perl -Ilib -Mthreads -lwe 'sub hi {eval "print q{Hi}"}; threads->new(\&hi)->join'

Session has some lines cut

Starting program: /home/nick/p4perl/perl/perl -Ilib -Mthreads -lwe sub\ hi\ \{eval\ \"print\ q\{Hi\}\"\}\;\ threads-\>new\(\\\&hi\)-\>join

Breakpoint 2, perl_clone (proto_perl=0x827a000, flags=2) at sv.c:10771
10771       CLONE_PARAMS* param = &clone_params;
(gdb) c
[Switching to Process 64007, Thread 1]

Breakpoint 1, Perl_pp_entereval (my_perl=0x829c000) at pp_ctl.c:3411
3411        dVAR; dSP;
(gdb) p sizeof(struct perl_memory_debug_header)
$7 = 12
(gdb) p my_perl->Tcurcop
$8 = (COP * volatile) 0x827890c
(gdb) x/3x 0x8278900
0x8278900:      0x0827a000      0x082958c0      0x08295880

(gdb) p my_perl->Iorigfilename
$12 = 0x83133fc "-e"
(gdb) x/3x 0x83133f0
0x83133f0:      0x0829c000      0x083280e0      0x083280c0

That column is the perl interpreter that the memory was allocated from.
Note that PL_origfilename is allocated from the current interpreter
(0x829c000) whereas PL_curcop is allocated from the parent interpreter
(0x827a000 - as seen from the call to perl_clone)

I assume that for the duration of the use of the optree in the child, the
parent is forbidden from cleaning up and destructing?

Nicholas Clark

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