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:

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
So you starting only one thread, which prints ten numbers and kills itself. Main thread without problems continue to run while(1) loop.

In reply to Re: continue after killing thread? by zwon
in thread continue after killing thread? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.