package Test; sub thr_func { my @args = @_; print('Thread started: ', join(' ', @args), "\n"); sleep $args[0]; return qw(all done); } 1; #### 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 #### 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 #### 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!