Why are you detaching your thread? I'd have to reread the docs, but I think
that's your problem. If you detach your thread, then the boss thread can't
keep track of it.

>From perlthrtut:

Ignoring A Thread

       join() does three things: it waits for a thread to exit, cleans up
after it, and returns any data
       the thread may have produced.  But what if you're not interested in
the thread's return values, and
       you don't really care when the thread finishes? All you want is for
the thread to get cleaned up
       after when it's done.

       In this case, you use the detach() method.  Once a thread is
detached, it'll run until it's fin-
       ished, then Perl will clean up after it automatically.

           use threads;

           $thr = threads->new(\&sub1); # Spawn the thread

           $thr->detach; # Now we officially don't care any more

           sub sub1 {
               $a = 0;
               while (1) {
                   $a++;
                   print "\$a is $a\n";
                   sleep 1;
               }
           }

       Once a thread is detached, it may not be joined, and any return data
that it might have produced (if
       it was done and waiting for a join) is lost.



------------------------------------------------------------------------


Yesterday, Tom Brettin wrote:

> I want to have a model where the boss sends the worker off to do some work.
> The worker does not need to communicate the results back to the boss.
> Meanwhile, the boss needs to report that the worker is working at regular
> intervals until the worker is done.
>
>     my $thread = threads->create(\&workerThread);
>     my $tid = $thread->tid;
>     $thread->detach();
>
>     while(1) {
>       print "worker thread $tid is busy\n";
>       sleep 3;
>       last unless threads->object($tid);
>     }
>
> The problem that I'm having is that the while loop never terminates. I
> thought that once the worker was done, the call to threads->object($tid)
> would return undef.
>
> How can the boss monitor the worker?
>
> Thanks for any help.
> Tom
>
>
>
>

----------------------------------------------------------
"Fun's over fellows. If you're going to beat up my friends
in my bar, there's a two-drink minimum." -- Moe --
----------------------------------------------------------

Reply via email to