in reply to Re^2: XS: exposing C++ library constant as package variable
in thread XS: exposing C++ library constant as package variable

Each thread will be accessing a different copy of it

I would have expected the copies to be identical, and that the SvREADONLY_on would ensure that they stay identical.
Of course, my expectations are often wrong - especially re threads. (IOW, someone please correct me where necessary.)

Cheers,
Rob
  • Comment on Re^3: XS: exposing C++ library constant as package variable

Replies are listed 'Best First'.
Re^4: XS: exposing C++ library constant as package variable
by Anonymous Monk on Oct 08, 2015 at 07:46 UTC
    yes, they're identical copies
    $ perl -le "sub LUCY(){66} use threads; async{ print join q/ /, thread +s->tid, LUCY(), \&LUCY() } for 1..3; sleep 1; " 1 66 SCALAR(0xb6c0d4) 2 66 SCALAR(0xbf7144) 3 66 SCALAR(0xc7eebc) Perl exited with active threads: 0 running and unjoined 3 finished and unjoined 0 running and detached

    $ perl -le "use Readonly; Readonly::Scalar $LU => 66; use threads; asy +nc{ print join q/ /, threads->tid, $LU, \$LU } for 1..3; sleep 1; " 1 66 SCALAR(0xb84cfc) 2 66 SCALAR(0xc1bbec) 3 66 SCALAR(0x10af0b4) Perl exited with active threads: 0 running and unjoined 3 finished and unjoined 0 running and detached
Re^4: XS: exposing C++ library constant as package variable
by ikegami (Patriarch) on Oct 08, 2015 at 17:29 UTC
    Of course they're identical copies; I was saying that each thread gets its own copy. Updated wording in this post's grandparent.