in reply to Re: Monitor list of threads running
in thread Monitor list of threads running

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Monitor list of threads running
by BrowserUk (Patriarch) on Apr 08, 2010 at 19:41 UTC
    It does not do anything with $thr.

    Exactly. You are throwing it (them, one for each thread you create) away. So don't do that, save them.

    my @threads; for (0 ..3)) { my $thr = threads->create( sub { worker(); } ); $thr->detach(); push @threads, $thr; } ... # then later for my $thr ( @threads ) { print 'Thread ', $thr->tid, $thr->is_running ? ' is running' : ' is not running';

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I did something similar: and I get this message. <bolckquote> Can't locate auto/threads/is_running.al in...
      foreach my $test (@all_threads) { if( $test->is_running() ) { print "Running: $test\n"; } }

        Which version of threads are you using?

Re^3: Monitor list of threads running
by Corion (Patriarch) on Apr 08, 2010 at 19:18 UTC

    So, maybe you want to do something with $thr, then, if you want to monitor the newly created thread? The threads documentation lists various uses for the return value of ->create(). Maybe now is a good time to read that documentation and look for these uses.

    Also, again, maybe you really don't want to ->detach threads but to just keep them around and ->join them. Just feed them from a Thread::Queue and wait until they have all finished as all work has been done. But then, I'm sure that approach has already been shown to you.

      I don't need the workerThreads to wait at all, I just want them in while loop and keep reading from DataQueue, and MasterThread to Just Queue to DataQueue.

      My only concern was to watch and make sure all workerThreads are alive.

      So, I don't know if I can use join() in my case

        Maybe now is a good time to review the threads documentation. The skeleton for a simple Thread::Queue worker approach is outlined by BrowserUk in 735931. Maybe you want to work from that, or do some more research into other posts on the subject on this site.