in reply to detach for threads

See perlthrtut
use threads; my $thr = threads->create(\&sub1); # Spawn the thread $thr->detach(); # Now we officially don't care any more sleep(15); # Let thread run for awhile sub sub1 { $a = 0; while (1) { $a++; print("\$a is $a\n"); sleep(1); } }

Replies are listed 'Best First'.
Re^2: detach for threads
by exilepanda (Friar) on Nov 15, 2011 at 09:46 UTC
    O! Thanks I got it now. It ends not because the thread has a problem, but the main() ends.
      As you experiment more with threads, you may see the warning " A thread exited while %d other threads were still running", that is caused by the main thread finishing before the spawned threads. Also watch out for using "exit" or "die" in thread code blocks, that will exit the entire program.

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh