in reply to ithreads not behaving as expected

This:  my $thr = threads->new(\sub1);

should be   my $thr = threads->new(\&sub1);

If you had warnings enabled, you'd've got:  Thread 1 terminated abnormally: Not a CODE reference at ...


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.
RIP PCW

Replies are listed 'Best First'.
Re^2: ithreads not behaving as expected
by BrowserUk (Patriarch) on Jul 16, 2009 at 23:38 UTC

    Then you will have to supply more information because what you've shown so far works as expected:

    #! perl -sw use 5.010; use strict; our $FLAG; if( $FLAG ) { require '780835-s.pl'; doit(); }
    #! perl -sw use 5.010; use strict; use threads; sub t{ say 'Hi from thread'; } sub doit { say 'Before'; my $t = threads->create( \&t ); say 'After'; } 1;
    C:\test>780835-m -FLAG=0 C:\test>780835-m -FLAG=1 Before After Hi from thread Perl exited with active threads: 1 running and unjoined 0 finished and unjoined 0 running and detached

    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.
Re^2: ithreads not behaving as expected
by madorb (Novice) on Jul 16, 2009 at 22:16 UTC
    sorry, that was a typo, it was correct in the real script. i'll update the above code.