#!/usr/bin/perl
use warnings;
use strict;
use threads;
use threads::shared;
print "Content-type: text/html\n\n";
print "Starting work
\n";
$|++;
# set a shared value of TRUE for running the progress bar
my $keepRunningProgressBar : shared = 1;
# Set the progress bar running indefinitely
my $progressBar = threads->create( \&dot_thread )->detach;
# Now do stuff in the work thread
my $threadForSpidering = threads->new( \&workthread );
#The work thread finished
#$threadForSpidering->join; #you have 3 threads, not just one
#main, dot_thread, and workthread
#And tells the progress bar to stop running
$keepRunningProgressBar = 0;
#<>; #without waiting here you get the thread exited error
foreach my $thread ( threads->list ) {
$thread->join;
}
print "done
.\n";
exit;
##########################################################
sub dot_thread {
$|++;
while ( $keepRunningProgressBar == 1 ) {
print ".\n";
sleep( 1 );
}
}
sub workthread {
for ( 1 .. 10 ) {
print "\tworking\n";
sleep 1;
}
}