Hi Perl Monks, Im working with perl 5.8.8. and when I do this
my $thr = threads->create(\&function); $thr->join; sub function { }
I get a error " Attempt to free unreferenced variable SV: " while 'joining' the thread I came to know that perl 5.10.0 solves this. But for some reasons I cant port it to newer version as all the softwares are built on 5.8.8. What I essentially need is the main thread has to wait for the child thread to finish. But I couldnt do with join as my interpreter encounters problem. So I tried to use the following code snippet which uses semaphores.
use threads; use threads::shared; use Thread::Semaphore; my $init = 0; my $sem:shared; $sem = new Thread::Semaphore($init); my $thr = threads->new(\& process ); $sem->down; sub process { lock($sem); $sem->up ; return; }
Here also once semaphore count is incremented by the thread the main thread immediately finishes its execution and I am getting "A thread finished while 2 threads were running" Thats because the exexution may shift to main thread before the return is called. Can someone help me out. I found out it is actually a bug with internal reference count. Refer this bug

In reply to Problem with threads + join by sumanth

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.