Hmm, ok, well it seems it comes back to the fact that perl does not wait
for threads to finish, so its more than likely the main process is
finishing before the threads have even begun to do anything.

Ray

-----Original Message-----
From: Elizabeth Mattijsen [mailto:[EMAIL PROTECTED]] 
Sent: 24 July 2002 15:02
To: Ray Hilton; 'Arthur Bergman'
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: what is the scope of detached threads?

At 02:51 PM 7/24/02 +0100, Ray Hilton wrote:
>Ok, I try:
>
>use threads;
>
>&foo;
>sub foo {
>         my $thr = threads->new(\&bar);
>         $thr->detach;
>}
>
>sub bar {
>         sleep(3);
>         print "bar\n";
>}
>
>And I get:
>
>A thread exited while 2 other threads were still running.

That's because there is no executable code after the &foo.  So it
reaches 
the end of the script immediately (before the 3 seconds of bar have 
elapsed) and executes an implicit exit.  Since an exit in any thread
will 
take down the entire process, including any other threads, bar will be 
interrupted before it ever gets the chance to print anything.  And
because 
there are threads running when you exit, you get the error 
message.  Confusing thing is that it says there are two, when in fact
there 
was only one (at least visible).  I guess that wrong number (still) is a
bug...


>And no evidence of bar\n being printed.  What is this create function
>you have?  Is that the same as new()?

create is a synonym for new (how's that for politics...  ;-)



Liz


Reply via email to