lelotto85 has asked for the wisdom of the Perl Monks concerning the following question:
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
And File thread.plpackage Test; sub thr_func { my @args = @_; print('Thread started: ', join(' ', @args), "\n"); sleep $args[0]; return qw(all done); } 1;
I run Apache 2 with mod_perl 2.0.4 on Ubuntu 11.04. My site is configured with these params: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
<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):
Could you help me to find the problem? ThanksContent-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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: cgi thread creation segfault
by Eliya (Vicar) on Dec 28, 2011 at 13:14 UTC | |
by lelotto85 (Initiate) on Dec 28, 2011 at 14:01 UTC | |
by Eliya (Vicar) on Dec 28, 2011 at 14:19 UTC | |
by mbethke (Hermit) on Dec 28, 2011 at 18:07 UTC | |
by lelotto85 (Initiate) on Dec 28, 2011 at 19:33 UTC | |
by mbethke (Hermit) on Dec 28, 2011 at 23:46 UTC | |
by lelotto85 (Initiate) on Dec 29, 2011 at 08:59 UTC | |
by lelotto85 (Initiate) on Dec 29, 2011 at 08:49 UTC |