### Program: threadTest2.pl ### use threads; use threads::shared; use CGI::Push qw/:standard/; # Shared variables my $progressThread1 : shared = 0; my $progressThread2 : shared = 0; my $progressThread3 : shared = 0; my $progressThread4 : shared = 0; my $progressThread5 : shared = 0; # Arrary of progress text @progress = ( 'No Activity....', 'Connecting.....', 'Searching......', 'Parsing........', 'Finished.......', 'Error..........', ); # Create threads $thr1 = threads->new(\&thread1); $thr2 = threads->new(\&thread2); $thr3 = threads->new(\&thread3); $thr4 = threads->new(\&thread4); $thr5 = threads->new(\&thread5); # Do not end program until all threads have finished $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); sub thread1 { sleep 6; screenDisplay( 1, 1 ); sleep 2; screenDisplay( 1, 2 ); sleep 4; screenDisplay( 1, 3 ); sleep 5; screenDisplay( 1, 4 ); } sub thread2 { sleep 8; screenDisplay( 2, 1); sleep 2; screenDisplay( 2, 2 ); sleep 4; screenDisplay( 2, 3 ); sleep 5; screenDisplay( 2, 4 ); } sub thread3 { sleep 3; screenDisplay( 3, 1 ); sleep 2; screenDisplay( 3, 2 ); sleep 4; screenDisplay( 3, 3 ); sleep 5; screenDisplay( 3, 4 ); } sub thread4 { sleep 10; screenDisplay( 4, 1 ); sleep 2; screenDisplay( 4, 2 ); sleep 4; screenDisplay( 4, 3 ); sleep 5; screenDisplay( 4, 4 ); } sub thread5 { sleep 1; screenDisplay( 5, 1 ); sleep 2; screenDisplay( 5, 2 ); sleep 4; screenDisplay( 5, 3 ); sleep 5; screenDisplay( 5, 4 ); } sub screenDisplay { my ( $thread, $status ) = @_; print $progress[$status], "Thread: $thread\n"; return undef; } ### Program: threadTest3.pl ### use threads; use threads::shared; use CGI::Push qw/:standard/; # Shared variables my $progressThread1 : shared = 0; my $progressThread2 : shared = 0; my $progressThread3 : shared = 0; my $progressThread4 : shared = 0; my $progressThread5 : shared = 0; # Arrary of site names @sites = ( '', 'Site One', 'Site Two', 'Site Three', 'Site Four', 'Site Five', ); # Arrary of progress text @progress = ( 'No Activity....', 'Connecting.....', 'Searching......', 'Parsing........', 'Finished.......', 'Error..........', ); # Create threads $thr1 = threads->new(\&thread1); $thr2 = threads->new(\&thread2); $thr3 = threads->new(\&thread3); $thr4 = threads->new(\&thread4); $thr5 = threads->new(\&thread5); # Do not end program until all threads have finished $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); sub thread1 { sleep 6; $progressThread1 = 1; screenDisplay(); sleep 2; $progressThread1 = 2; screenDisplay(); sleep 4; $progressThread1 = 3; screenDisplay(); sleep 5; $progressThread1 = 4; screenDisplay(); } sub thread2 { sleep 8; $progressThread2 = 1; screenDisplay(); sleep 2; $progressThread2 = 2; screenDisplay(); sleep 4; $progressThread2 = 3; screenDisplay(); sleep 5; $progressThread2 = 4; screenDisplay(); } sub thread3 { sleep 3; $progressThread3 = 1; screenDisplay(); sleep 2; $progressThread3 = 2; screenDisplay(); sleep 4; $progressThread3 = 3; screenDisplay(); sleep 5; $progressThread3 = 4; screenDisplay(); } sub thread4 { sleep 10; $progressThread4 = 1; screenDisplay(); sleep 2; $progressThread4 = 2; screenDisplay(); sleep 4; $progressThread4 = 3; screenDisplay(); sleep 5; $progressThread4 = 4; screenDisplay(); } sub thread5 { sleep 1; $progressThread5 = 1; screenDisplay(); sleep 2; $progressThread5 = 2; screenDisplay(); sleep 4; $progressThread5 = 3; screenDisplay(); sleep 5; $progressThread5 = 4; screenDisplay(); } sub screenDisplay { print $progress[$progressThread1], $sites[1], "\n"; print $progress[$progressThread2], $sites[2], "\n"; print $progress[$progressThread3], $sites[3], "\n"; print $progress[$progressThread4], $sites[4], "\n"; print $progress[$progressThread5], $sites[5], "\n\n"; }