sumanth has asked for the wisdom of the Perl Monks concerning the following question:
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.my $thr = threads->create(\&function); $thr->join; sub function { }
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 buguse 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with threads + join
by moritz (Cardinal) on Jun 07, 2008 at 09:47 UTC | |
|
Re: Problem with threads + join
by BrowserUk (Patriarch) on Jun 07, 2008 at 19:17 UTC | |
|
Re: Problem with threads + join
by zentara (Cardinal) on Jun 07, 2008 at 16:05 UTC |