#!C:/Perl/bin/perl -w
use strict;
use threads;
use threads::shared;
print "Starting main program\n";
my @threads;
for ( my $count = 1; $count <= 5; $count++)
{
my $t = threads->new(\&sub1, $count);
push(@threads, $t);
}
foreach (@threads)
{
my $num = $_->join;
}
print "End of main program\n";
sub sub1
{
my $num = shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "$num thread started at $hour:$min:$sec\n";
open FILE, ">$num.txt" or die $!;
print FILE "$num.txt was created at $hour:$min:$sec.\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print FILE "$num.txt was closed at $hour:$min:$sec.\n";
close FILE or die $!;
return $num;
}
use strict;
use threads;
use threads::shared;
print "Starting main program\n";
my @threads;
for ( my $count = 1; $count <= 5; $count++)
{
my $t = threads->new(\&sub1, $count);
push(@threads, $t);
}
foreach (@threads)
{
my $num = $_->join;
}
print "End of main program\n";
sub sub1
{
my $num = shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "$num thread started at $hour:$min:$sec\n";
open FILE, ">$num.txt" or die $!;
print FILE "$num.txt was created at $hour:$min:$sec.\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print FILE "$num.txt was closed at $hour:$min:$sec.\n";
close FILE or die $!;
return $num;
}