Hypothesis: SVs are owned by the tread in which they were created. When a thread exits, any SVs it owns are freed.

Nice hypothesis!++

By the way, using a string buffer to store a pointer is a waste. An IV is guaranteed to be big enough. Or you can use the PV itself (using SvPV_set) if you set LEN to zero.

Indeed. Or, as RVs and IVs are now aliases for the same thing, skip the intermediary completely, which appears to fix the problems Update: No it doesn't. I was so happy to see the back of the panic, that I missed that the contained value is updated by the thread :(

#! perl -slw use strict; package O; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'xso', CLEAN_AFTER_BUILD => 0; typedef struct { SV**sv; } O; void *mem( size_t size ) { void *p; Newx( p, size, char ); return p; } SV *new( char *package ) { O *o = (O*)mem( sizeof( O ) ); SV *rv = newRV( o ); o->sv = mem( sizeof( SV* ) ); sv_bless( rv, gv_stashpv( package, 0 ) ); SvREADONLY_on( rv ); printf( "N:rv:%p o:%p\n", rv, o ); return rv; } int set( SV *rv, SV *in ) { O *o = *(O**)SvRV( rv ); printf( "S:rv;%p o:%p\n", rv, o ); o->sv = newSVsv( in ); return 1; } SV *get( SV *rv ) { O *o = *(O**)SvRV( rv ); SV *old = newSVsv( o->sv ); SvREFCNT_inc( old ); printf( "G:rv;%p o:%p old:%p\n", rv, o, old ); return old; } void DESTROY( SV *rv ) { printf( "DESTROY:%s\n", SvPV_nolen( rv ) ); } void CLONE( SV *rv ) { printf( "CLONE:%s\n", SvPV_nolen( rv ) ); } END_C package main; use threads; use Devel::Peek; my $o = O->new(); print $o; $o->set( "abcde" ); print $o->get(); print "\nthreaded\n"; async { $o->set( "12345" ); }->join; print $o->get(); __END__ C:\test>xso N:rv:000000000025E128 o:00000000040D6738 O=SCALAR(0x40d6738) S:rv;000000000025E248 o:0000000003CB6088 G:rv;000000000025E248 o:0000000003CB6088 old:00000000002B7980 abcde threaded CLONE:O S:rv;0000000004361010 o:000000000432F5F8 DESTROY:O=SCALAR(0x4361028) G:rv;000000000025E248 o:0000000003CB6088 old:00000000002B79E0 abcde DESTROY:O=SCALAR(0x40d6738)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^4: semi-panic: attempt to dup freed string? by BrowserUk
in thread semi-panic: attempt to dup freed string? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.