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

As for caveats with regard to threading

It's a normal Perl scalar. It will get cloned on thread creation like every other. Each thread will be accessing its own copy of it. No problem.

Update: s/a different/its own/

  • Comment on Re^2: XS: exposing C++ library constant as package variable

Replies are listed 'Best First'.
Re^3: XS: exposing C++ library constant as package variable
by syphilis (Archbishop) on Oct 08, 2015 at 05:27 UTC
    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
      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
      Of course they're identical copies; I was saying that each thread gets its own copy. Updated wording in this post's grandparent.