I'm looking to share a blessed reference to any arbitrary lump of memory--the struct in this example.
That's not very clear. There is no shared reference, and the blessed scalar contains a string, not a reference.
SV = IV(0x982f560) at 0x982f564 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x9814874 SV = PVMG(0x9863320) at 0x9814874 REFCNT = 2 FLAGS = (OBJECT,POK,READONLY,pPOK) IV = 0 NV = 0 PV = 0x982a504 "T&\316\t"\0 CUR = 4 LEN = 8 STASH = 0x982f534 "O"
I'm going to assume you meant "I'm looking to share an arbitrary lump of memory--the struct in this example."
You already succeeded in doing that. «o» in both threads and thus «*o» is the same too.
int set( SV *rv, SV *in ) { O *o = *(O**)SvPV( SvRV( rv ), PL_na ); o->sv = newSVsv( in ); printf( "S:rv;%p o:%p o->sv:%p\n", rv, o, o->sv ); return 1; } SV *get( SV *rv ) { O *o = *(O**)SvPV( SvRV( rv ), PL_na ); printf( "G:rv;%p o:%p o->sv:%p\n", rv, o, o->sv ); return newSVsv( o->sv ); } S:rv;0x8d1c9f4 o:0x87736f4 o->sv:0x8d1d374 G:rv;0x8641564 o:0x87736f4 o->sv:0x8d1d374
The problem isn't with sharing an arbitrary lump of memory. The problem is you're trying to share something you don't own and gets destroyed by the owner (the thread's Perl interpreter) when it exits.
I think that I should be able to prevent the SvUV being destroyed prematurely by having it's refcount incremented
Reference counts don't matter in global destruction. Well, it might affect the order in which scalars get destroyed, but it won't prevent it from getting destroyed.
If you were to create the SV in the receiver, then it would work.
Update: Minor touch-ups for clarity.
In reply to Re^7: semi-panic: attempt to dup freed string?
by ikegami
in thread semi-panic: attempt to dup freed string?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |