I'm using multithreading in a Perl script. However, I get segmentation fault and I believe its when the threads are joined. I'm not sure what I might be doing wrong. I have used print statements to indicate when threads start and end and a print statement in the join block and finally the print statement to indicate the end of the program. Here's a snippet.
#!/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()) { #initiated IPAM session my @retrieved_objs = #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;
In reply to segmentation fault issue while joining threads in perl by userr_1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |