Hi, i'm trying to create a cgi script that works with threads. The problem is that my little script works perfectly when i run it from command-line but, as soon as a try to call it from my browser, I get a [notice] child pid 7715 exit signal Segmentation fault (11) in apache log. I saw that the Segfault is thrown exactly when I create a new thread

Here is the code. File Test.pm

package Test; sub thr_func { my @args = @_; print('Thread started: ', join(' ', @args), "\n"); sleep $args[0]; return qw(all done); } 1;
And File thread.pl
use threads; use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Test; print header('text/html'); my $r = shift; my $MAX_THREADS = 5; my @res; for my $i (1 .. $MAX_THREADS) { threads->create('Test::thr_func', $i*2); } print "Here I am!\n"; while (threads->list()) { sleep 1; print "running...\n"; foreach my $thread (threads->list(threads::joinable)) { if($thread->is_joinable()) {; push(@res, $thread->join()); } } } print "That's all folks!\n"; #Here goes the end of html code
I run Apache 2 with mod_perl 2.0.4 on Ubuntu 11.04. My site is configured with these params:
<Directory "/var/www/cgi-bin"> SetHandler perl-script PerlResponseHandler ModPerl::PerlRun #PerlResponseHandler ModPerl::Registry PerlHandler Apache::Registry PerlOptions +ParseHeaders +GlobalRequest AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>

Running from command-line the output is (as aspected):

Content-Type: text/html; charset=ISO-8859-1 Thread started: 4 Thread started: 2 Thread started: 6 Thread started: 8 Here I am! Thread started: 10 running... running... running... running... running... running... running... running... running... running... That's all folks!
Could you help me to find the problem? Thanks


In reply to cgi thread creation segfault by lelotto85

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.