in reply to Event module and threads/fork segfault on Win32

You are more likely to get help if you post your code, or a subset of it that demostrates the problem, than if you expect potential helpers to try and re-create your code from this sparse description of it.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Event module and threads/fork segfault on Win32

Replies are listed 'Best First'.
Re^2: Event module and threads/fork segfault on Win32
by gurbo (Sexton) on Jun 05, 2007 at 03:17 UTC
    You're right. Here it is the quintessence of the problem:
    #!/usr/bin/perl use strict; use warnings; use threads; sub create_thread { warn "in create_thread() before async()\n"; my $thr = async { warn "in thread\n"; }; warn "in create_thread() before join()\n"; sleep 2; $thr->join; warn "in create_thread() before return\n"; return; } use Event; my $timer = Event->timer( cb => \&create_thread, after => 2); warn "starting event loop\n"; Event::loop;

    When create_thread() returns, the interpreter segfaults.
    The problem seems to be caused when join() is called, if you comment the call, the event loop ends and you get the warning:
    Perl exited with active threads: 0 running and unjoined 1 finished and unjoined 0 running and detached

      The next question is which versions of Perl, threads and Event are you using?

      I just ran your script under AS811/5.8.6 with threads v1.05 and Event v1.09 and it completed without a segfault, and just a warning for a leaked scalar?

      C:\test>619259.pl starting event loop in create_thread() before async() in create_thread() before join() in thread in create_thread() before return Scalars leaked: 1 C:\test>perl -v This is perl, v5.8.6 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 811 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 13 2004 09:52:01 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\test>perl -Mthreads -e"warn "$threads::VERSION" 1.05 at -e line 1. C:\test>perl -MEvent -e"warn "$Event::VERSION" 1.09 at -e line 1.

      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.
        This is interesting... I'm running newer versions of everything...
        C:\>perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread (with 50 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Binary build 820 [274739] provided by ActiveState http://www.ActiveSta +te.com Built Jan 23 2007 15:57:46 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\>perl -MEvent -e"print qq($Event::VERSION\n)" 1.08 C:\>perl -Mthreads -e"print qq($threads::VERSION\n)" 1.58
        The OS is WinXP Professional SP2 running in a VMWare VM v5.5.51 build-19175

        The real code starts threads in one watcher and joins them in another to collect their exit statuses. In that situation it gets the "leaked scalar" before the segfault.