Hi, guys

Recently I just wanna write a simple multi-threaded perl program.

The environment which the script runs in is
OS: Linux i386
perl: 5.8.7
thread.pm : 1.05

And I find that when I create a child thread, detach from it and exit,
the warning message shows up: A thread exited while 2 threads were
running.
And I find in the user doc of threads:

" If the program exits without all other threads having been either
joined or detached, then a warning will be issued. (A program exits
either because one of its threads explicitly calls exit(), or in the
case of the main thread, reaches the end of the main program file.) "

It seems the warning message couldn't have been shown up. I try to use
join,
it works as stated, I wonder why? Anybody could help me out of this?

Thanks very much.

The test scripts is as follow for your kind reference.

#! /usr/bin/perl -w
use threads;

my @p1=("a","b","c","d");

$thr=threads->new(\&test,[EMAIL PROTECTED],"Hello","World");
print " current thread id:".threads->tid().".\n";
print " child thread id:".$thr->tid.".\n";
$thr->detach();
#$thr->join();

sub test{
        my ($p1,$p2,$p3)[EMAIL PROTECTED];
        my @[EMAIL PROTECTED];

        print "p1:@p1\n";
        print "p2:$p2\n";
        print "p3:$p3\n";

        sleep 10;
}                  

Regards,
Zhengyu Li

Reply via email to