On måndag, juni 3, 2002, at 10:16 , Elizabeth Mattijsen wrote:

> At 09:57 AM 6/3/02 +0200, Arthur Bergman wrote:
>>> Well, the thread should have finished after the detach.  I guess I'm 
>>> still thinking too linear in this respect and not parallel 
>>> enough...  ;-)
>> No, actually the thread is running and then detaching, then finding 
>> out it there is no more to do then it destructs itself. What happens 
>> here is that somewhere between the threads ending and the completeness 
>> of the destruct the kernel switches back to the original thread, which 
>> runs of the main program and quits it, when the main program quits it 
>> will start clearing up all the memory for the process, then while it 
>> is busy with this, the kernel once again preempts and gives control 
>> back to the second thread, which now tries to complete destruction but 
>> the memory underneath has been deleted, now bad things happen.
>
> Shouldn't the main program wait until all the threads are finished 
> before taking down itself?  I realise that this may cause a hang if the 
> threads never finish, but maybe it should at least wait one second, or 
> maybe even 5 seconds (as that seems to fix the errors) before it starts 
> to take itself down and everything with it?  This would be similar to 
> Apache restarts, where children get an X-amount of time to finish up 
> themselves before getting axed if they don't.  Could be as simple as a 
> "sleep 1" before the exit of thread 0.
>

We have had this discussion on p5p before, I am of the opinion that we 
should wait, some people want it customizable via options to threads.pm

This won't happen for 5.8, however it is possible to do from perl 
without hacking in the core and release on cpan, threads::exitcontrol; 
or something like that.

>
>>>> And yes the warnings look scary, but they aren't as scary when you 
>>>> realize that perl is trying to run a globaldestruct on a perl
>>>> interpreter that has already been wiped out by the OS.
>>> Well, I can live with the warnings  ;-), but the hang that I 
>>> experienced about 1 in 10 times, _is_ pretty scary to me for a 
>>> production environment...
>> I will try to fix the code to give the warning for detached and 
>> exiting threads, but a good rule of thumb is to always make sure all 
>> your threads are done before exiting.
>
> Should I send proposal patches for perlthrtut to you or to Dan Sugalski?
>
>

Please send them perl5 porters.

Arthur

Reply via email to