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
David Mertens
December 5, 2012 03:15
Re: Undefined thread object for main thread (tid zero) even thoughthe main thread exists
Message ID:
Mike -

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 here: At any rate, I
will soften the condition on thread existence to allow for the zeroeth
thread to pass through.

I think I have enough of an answer to move forward for now. However, ideas
and comments are welcome! Also, I would be more than happy to discuss the
details if anybody would like to hear. I'm going to begin, however, by
presuming that the list doesn't want too much noise. :-)



On Mon, Dec 3, 2012 at 8:47 AM, Mike Pomraning <>wrote:

> On Sun, Dec 2, 2012 at 10:53 PM, David Mertens <>wrote:
>> ----%<----
>> defined (threads->object($originating_tid{$name}))
>>     or croak("retrieve_pdls: '$name' was created in a thread that "
>>     . "is no longer available");
>> ---->%----
>> In my test suite, I create and store data in the main thread. For this
>> example, then, $originating_tid{$name} == 0 for all cases considered. The
>> problem is that only the main thread is capable of retrieving the threads
>> object for tid 0. Any other (child) thread gets an undefined value. Does
>> that surprise anyone? Are child threads able to get the thread objects for
>> their parents or siblings?
> I might be misreading this, but I believe that threads->object() ignores
> detached threads unless a tid is explicitly passed in *and* that tid is the
> tid of the calling thread.  The main thread is detached, so no thread other
> than tid 0 can look it up via object().
> (You describe an interesting problem and approach; do you have
> demonstration code that others can take a look at?)
> -Mike

 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About