could you explain why it is owned by other thread, when i am calling it from with only thread i have created,
You have only created one thread, but every process starts with one thread, so now you have two.
My guess is--if you posted the code, we wouldn't have to guess--that you have something like this:
use threads; use DBI; my $dbh = DBI->connect('dbi:DBM:'); ... my $thread = threads->create( \&thread ); ... sub thread { ... $sql = $dbh->prepare($query) || die($dbh->errstr); #55 ... }
When the new thread is created, Perl clones (creates a copy of) the perl scalar that contains the DB handle for use by that new thread, but as the DBD driver you're using doesn't have a CLONE method, only the handle is cloned, not the object that lives behind it.
So, when you attempt to use the cloned handle within the new thread, DBI is detecting that it was created for a different thread and is telling you--very clearly--that that isn't going to work.
One workaround would be to move the creation of the handle--ie. the DBI->connect(...) into the thread also. But be aware that it will mean not using DBI from your main thread. And if your thread is short lived and created repeatedly, then it will cost you the process of reconnected each time, which may or may not be a problem.
Please note the "My guess is" up front and take this speculation in knowledge of it. If you posted the code, you'd be more likely to get a definitive answer.
In reply to Re: Threads and handle sharing
by BrowserUk
in thread Threads and handle sharing
by gemoroy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |