#!/usr/bin/perl #use DBI; use POSIX; #use Data::Dumper; #use Fcntl ':flock'; use strict; use warnings; use threads; use threads::shared; #use "some IPAM system's package name"; my $host = "1.1.1.1"; my $database = "some_db"; my $user = "some_user"; my $pswd = "some_pswd"; my @threads; #my $dbh = DBI->connect("DBI:mysql:$database;host=$host", $user, $pswd ,) || die "Could not connect to database: $DBI::errstr"; #$dbh->{'mysql_auto_reconnect'} = 1; my $sql = qq{ #a select statement }; #my $sth = $dbh->prepare($sql); #$sth->execute(); my $rows = 0; my @uni_array; #while(my @request = $sth->fetchrow_array()) for( 1 .. 10 ) { #initiated IPAM session my @retrieved_objs = ( 1..10 ); #searching for some results push @uni_array, @retrieved_objs; foreach(@retrieved_objs) { $rows++; } } my $number = $rows/10; my $ceil = ceil($number); for ( my $count = 1; $count <= $ceil; $count++) { my $t = threads->new(\&sub1, $count); push(@threads,$t); } foreach (@threads) { my $num = $_->join(); print "done with $num\n"; } print "End of main program\n"; sub sub1 { my $num = shift; print "started thread $num\n"; #some code sleep($num); print "done with thread $num\n"; return $num; } #$sth->finish(); #$dbh->disconnect; __END__ C:\test>junk28 started thread 1 started thread 2 started thread 3 started thread 4 started thread 5 started thread 6 started thread 7 started thread 8 started thread 9 started thread 10 done with thread 1 done with 1 done with thread 2 done with 2 done with thread 3 done with 3 done with thread 4 done with 4 done with thread 5 done with 5 done with thread 6 done with 6 done with thread 7 done with 7 done with thread 8 done with 8 done with thread 9 done with 9 done with thread 10 done with 10 End of main program