cristi1979 has asked for the wisdom of the Perl Monks concerning the following question:
Also I think I understand the following error, but can I get a clean exit somehow?#!/usr/bin/perl use threads; sub something_1 { my $thr; foreach (1..10){ my $q = threads->create(\&something_2, $_); $thr->{$_} = $q; } while (1) { foreach (keys %$thr) { if ($thr->{$_}->is_joinable()){ $thr->{$_}->join(); delete $thr->{$_}; } } print "trying:". (scalar keys %$thr)."\n"; last if not scalar keys %$thr; sleep 1; } } sub something_2 { my $a = shift; my $pid = fork(); if ($pid==0) { print "cocot $a\n"; exit(0); } else { waitpid($pid, 0); print "done $a\n"; } } # my $q = threads->create(\&something_1); something_1;
EDIT post a simpler example. the original one was with a fork from a thread from a threadPerl exited with active threads: 9 running and unjoined 0 finished and unjoined 0 running and detached
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problems with fork from thread
by DrManhattan (Chaplain) on Mar 01, 2012 at 16:43 UTC | |
by cristi1979 (Novice) on Mar 01, 2012 at 17:49 UTC | |
by BrowserUk (Patriarch) on Mar 02, 2012 at 07:06 UTC | |
by cristi1979 (Novice) on Mar 02, 2012 at 07:40 UTC | |
by Gangabass (Vicar) on Mar 04, 2012 at 02:49 UTC | |
| |
by Gangabass (Vicar) on Mar 02, 2012 at 06:42 UTC | |
|
Re: problems with fork from thread
by cristi1979 (Novice) on Mar 01, 2012 at 15:18 UTC | |
|
Re: problems with fork from thread
by zentara (Cardinal) on Mar 01, 2012 at 19:37 UTC | |
by Eliya (Vicar) on Mar 01, 2012 at 21:04 UTC |