Elizabeth Mattijsen wrote:
At 10:15 -0800 1/12/04, Stas Bekman wrote:

Elizabeth Mattijsen wrote:

At 10:00 -0800 1/12/04, Stas Bekman wrote:

% perl-5.8.3-ithread -le 'use threads; threads->new(sub { sleep 1})->detach for 1..1'
A thread exited while 2 threads were running.

Ah. That! That is considered to be correct behaviour (unless you're referring to the "2" instead of "1").

What's correct about it? I've detached the threads and shouldn't get any errors.


The problem is not in the detach. the problem is that your program finishes before all the threads have finished. This was discussed extensively on p5p in the summer of 2002 prior to the 5.8.0 release. The problem is that a thread cannot continue if any other thread does an exit(). To indicate that you're doing that, the message occurs. Only problem is that the hidden thread that's used to store shared values, is counted as well.

One could argue that detached threads shouldn't be counted. But, as I said, a detached thread is also yanked from existence as soon as any other thread does an exit().


Hope this explains it a bit.

Thanks, Liz. But how do we deal with this problem. Should I always finish threads programs with:


$_->join() for threads->list();

but that won't work with detached threads, since list() will return only a list of non-detached threads.

So I think we need to have a new blocking call that will prevent the main program/thread from exiting till all child threads are done.

The bottom line is that I don't want to see that error/warning message in my programs. Ideas?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to