You actually doesn't try to continue in the main thread. And BTW do you really understand what is your program doing? I've added some debugging output, so you could see that your program doesn't run many threads:
So you starting only one thread, which prints ten numbers and kills itself. Main thread without problems continue to run while(1) loop.use strict; use warnings; use threads; # Signal Handler $SIG{'KILL'} = sub { printf( " %3d <- Killed\n", threads->tid() ); threads->exit(); }; StartThread(); while (1) { warn "Here we continue in main thread"; sleep 1; } sub StartThread { # actually "Starting thread" is not correct here warn "Starting thread ", threads->tid, "\n"; my @threads = threads->list(); warn "Threads to kill: ", join ',', map { $_->tid } @threads; # Check to see if there any running threads # Note, that only main thread can survive this loop # any other thread will kill itself foreach (@threads) { print "Killing thread ... "; $_->kill('KILL'); print "Done\n"; } # Spawn new thread my $worker = threads->create( \&StartTest ); warn "exiting thread ", threads->tid; } sub StartTest { print "I: $_\n" for ( 0 .. 10 ); StartThread(); } __END__ Starting thread 0 Threads to kill: at 813428.pl line 22. exiting thread 0 at 813428.pl line 33. Here we continue in main thread at 813428.pl line 15. I: 0 I: 1 I: 2 I: 3 I: 4 I: 5 I: 6 I: 7 I: 8 I: 9 I: 10 Starting thread 1 Threads to kill: 1 at 813428.pl line 22. Killing thread ... 1 <- Killed Here we continue in main thread at 813428.pl line 15. Here we continue in main thread at 813428.pl line 15. Here we continue in main thread at 813428.pl line 15. ^C
In reply to Re: continue after killing thread?
by zwon
in thread continue after killing thread?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |