kcella has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to create a program that will spawn some worker threads for me, but I can never seem to get them to work. Here is basically what i want to do:
foreach my $key ( keys %$work ) { my $cap_run = $work->{ $key }->{ captured_run_name }; my $status = $work->{ $key }->{ statuscode }; push( @threads, threads->create( sub{ sleep 10; print "in thread +"; return 1; }, $key, $cap_run, $status ) ); } foreach my $thr ( @threads ) { push( @results, $thr->join ); }
Everytime I run this, I get the following error (on platform win32): Can't undef active subroutine during global destruction.

Any ideas?

thanks, Kevin

Replies are listed 'Best First'.
Re: perl ithreads join help!!
by NetWallah (Canon) on May 22, 2004 at 03:22 UTC
    Here is some working Win32 thread code that you can start from:
    use strict; use threads; my @MyThread; my $threadcount = 15; for (0..($threadcount-1)){ $MyThread[$_]=threads->new(\&s,$_,10+$_); }; if ($ARGV[0] eq 'a'){ foreach (@MyThread){ print qq(Return check via thread array from ) . $_->join() . qq(\n +); } }else{ foreach (threads->list()){ print qq(Return check via threads list from ) . $_->join() . qq(\n +); } } ####################### sub s{ my $a=shift; sleep($threadcount-$a); print qq(In sub s param=$a\n); return shift() }
    ANd some code that does something semi-useful with threads ..

    Offense, like beauty, is in the eye of the beholder, and a fantasy.
    By guaranteeing freedom of expression, the First Amendment also guarntees offense.
Re: perl ithreads join help!!
by dave_the_m (Monsignor) on May 21, 2004 at 22:12 UTC
    Which version of Perl are you using? And can you provide a complete but stripped-down script that reproduces the problem?
      Perl v5.6.1 -- the code I posted with my question is a stripped down version. Once the threads return, I cleanup and end the script.

      thanks,
      Kevin

        iThreads were still far from fully functional in v5.6.1, or (IMO) anytime bfore 5.8.3.

        If you want to do anything serious with iThreads, you should really look to upgrading to 5.8.3 or later. Many, many earlier bugs have been fixed.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        the code I posted with my question is a stripped down version.
        Ahem - I asked for a "complete but stripped-down script"; what you provided in your orignal posting isn't a complete executable script.
Re: perl ithreads join help!!
by fluxion (Monk) on May 22, 2004 at 04:35 UTC
    I didn't have any problems running the code in linux/perl5.8.4 I assume the error has something to do with the script exiting while a thread is still running, but the $thr->join should prevent that.

    Roses are red, violets are blue. All my base, are belong to you.