develooper Front page | perl.ithreads | Postings from December 2012

Re: Undefined thread object for main thread (tid zero) even thoughthe main thread exists

Thread Previous | Thread Next
From:
Mike Pomraning
Date:
December 5, 2012 04:02
Subject:
Re: Undefined thread object for main thread (tid zero) even thoughthe main thread exists
Message ID:
CAPZFfA_tCn5K-LRiTTeLFmzCL528jjYoV5DwQ3Ra2wbSDdBdmQ@mail.gmail.com
On Tue, Dec 4, 2012 at 9:15 PM, David Mertens <dcmertens.perl@gmail.com>wrote:

> Thanks for the explanation. Can you think of any way (apart from hackery)
> that I could check that a detached thread with the given tid exists? I do
> not need to manipulate it, I just need to know if it exists. I might
> consider tracking the existing threads through a shared array, but then I
> would have to modify the content of that shared array in an END block,
> which seems to be discouraged <<SNIP>>
>

You could wrap every user-supplied entry point function in your own
enclosing, anonymous sub for bookkeeping.  This sub is the true entry point
passed to threads->create(), and it touches `our %Tids : shared` before and
after invoking the user-supplied sub.  Thread 0 is still a special case.

Liz's Thread::Exit has an example of this approach.

-Mike

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About