For Programmers: Free Programming Magazines  


Home > Archive > ithreads > October 2005 > help why warning with detached thread









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author help why warning with detached thread
lzyiii@hotmail.com

2005-10-20, 7:59 am

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,\@p1,"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)=@_;
my @p1=@{$p1};

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

sleep 10;
}

Regards,
Zhengyu Li

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com