Thread

Posted on Wed May 30 17:08:35 2007 by jc2001
is_running is returning true when thread is killed externally.
I am starting a series of detached threads and I save the thread object in a hash as follows:
my $thr = threads->new(...); if ($thr) { my $nThreadTid = $thr->tid(); $aActiveThreads{$nThreadTid} = $thr; }
Periodically I check if specific threads are still running as follows:
my $thr = $aActiveThreads{$nThreadTid}; if($thr and $thr->is_running ) { #thread is running ... }

This works well and detects exits from the perl process OK, however I have found that if I kill the thread externally (I used process explorer) the $thr->is_running still returns true even though the thread has definitely been killed and is no longer outputting log messages etc.

I am using threads version 1.59 on Windows with perl 5.8.8 built by a colleague of mine.
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform: osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef

Im not sure whether this is a bug or usage issue. Any suggestions would be most welcome.
JC
Direct Responses: 5274 | Write a response
Posted on Wed May 30 18:22:22 2007 by jdhedden in response to 5271
Re: is_running is returning true when thread is killed externally.
> I have found that if I kill the thread externally
> (I used process explorer)

Eew! Yuck! Bad programmer! No cookie!

From 'perldoc perlthrtut':
What kind of threads are Perl threads? If you have experience with other thread implementations, you might find that things aren't quite what you expect. It's very important to remember when dealing with Perl threads that *Perl Threads Are Not X Threads* for all values of X. They aren't POSIX threads, or DecThreads, or Java's Green threads, or Win32 threads. There are similarities, and the broad concepts are the same, but if you start looking for implementation details you're going to be either disappointed or confused. Possibly both.
> the $thr->is_running still returns true

Since you mucked with Perl's threads externally, you compromised Perl's ability to track its threads' status.
Write a response