Trouble With MySQL and iThreads

Trouble With MySQL and iThreads

am 19.09.2003 09:38:44 von Steve Schein

All:

At the suggestion of Jochen Wiedmann I am posting a message to this
mailing list.

I am currently using MySQL 4.0x on a Linux system and Perl
v5.8 (threads enabled). At the moment I'm using a generic DBI module
(v1.38) and having trouble threads. The database won't connect on a new
thread and generates the error message:

"thread failed to start: DBD::mysql::dr connect failed: handle 1 is
owned by thread 8454df8 not current thread 86bc3d0 (handles can't be
shared between threads and your driver may need a CLONE method added) at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.p m line 585,
<$client> line 1."

While the actual program is a bit cumbersome, I was able to simulate the
error with the test code copied below. Clearly, in order to test it you
will need to supply your own database name, username, password and
table.

Thank you for taking the time to assist me.

Steve



#!/usr/bin/perl -w

# 9/19/03 - Error simulation program for running connections to MySQL on
threads

$|++;
use strict;
use warnings;

use threads;
use DBI;
#use DBD::mysql;

my ($db_name, $db_user, $db_pass, $statement);


#-----------MAIN------------

my $spawn_thr1 = threads->create(\&thread1);

while (1) {} # keep main thread alive


#-----------sub thread1------------


sub thread1 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh1 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers";

my $ary_ref1 = $dbh1->selectall_arrayref($statement);
my @sub_array1 = @$ary_ref1;
my $num_rows1 = @sub_array1;
print "The number of rows in the table are: $num_rows1\n";

my $rc1 = $dbh1->disconnect;

my $spawn_thr2 = threads->create(\&thread2)->detach;


} # end sub thread1


#-----------sub thread2------------

sub thread2 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh2 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers"; #

my $ary_ref2 = $dbh2->selectall_arrayref($statement);

my @sub_array2 = @$ary_ref2;
my $num_rows2 = @sub_array2;
print "The number of rows in the table are: $num_rows2\n";

my $rc2 = $dbh2->disconnect;


} # end sub thread2




--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org