Right. Now i'm trying to set up threads::shared $dbh. No good so far.
This class is used as a base for all my cdbi classes:
package Probe::DBI;
use strict;
use warnings;
use threads;
use threads::shared;
use base qw(Class::DBI::MSSQL);
my $dbh;
share($dbh);
$dbh = &share({});
bless($dbh, __PACKAGE__.'::db');
sub db_Main {
unless ($dbh->{Active}) {
$dbh = &share(DBI->connect_cached('dbi:ODBC:DRIVER={SQL Server
+};Server=moproj24;TargetDSN=probe', 'pr_user', 'pr_user', { __PACKAGE
+__->_default_attributes() }));
}
return $dbh;
}
The problem, i suppose, that $dbh is counted as a scalar, not as db handle object.
dbih_getcom handle threads::shared::tie=SCALAR(0x200f4d4) is not a DBI handle at c:/Perl/site/lib/Im
a/DBI.pm line 381.
Compilation failed in require at Probe/ProbeTask.pm line 10.
BEGIN failed--compilation aborted at Probe/ProbeTask.pm line 10.
Compilation failed in require at Probe/ProbeUser.pm line 11.
BEGIN failed--compilation aborted at Probe/ProbeUser.pm line 11.
Compilation failed in require at ./probe.pl line 9.
BEGIN failed--compilation aborted at ./probe.pl line 9.
Can you explain me how to get work?
Thanks,
Artem A. Avetisyan.
| [reply] [d/l] |
You cannot share DB-handles ($dbh) across threads. No matter what you do, you can't. What you're currently running afoul of is the fact that, as far as I understand the threads::shared documentation, it does not share variables deeply, and likely the hash will contain nested subhashes.
Even if you succeeded with that, you will run against the problem that the XS portions of DBI and the DBD are not threadsafe. Also read the below remarks that using multiple threads for concurrent DB access will not improve performance anyway.
| [reply] [d/l] |