Avatar billede emmek Nybegynder
28. august 2002 - 09:11 Der er 1 kommentar og
1 løsning

Accessing MySql from a perl thread (Ithreads) Possible or not..

Hey! Jeg har postet spørgsmålet til nogle nyhedsgrupper også, så derfor er det altså på engelsk, håber det går
Avatar billede emmek Nybegynder
28. august 2002 - 09:11 #1
Hi!

First of all I'm kindof new to perl, but know basic programming structures,
such as basic, C++, Java, ASM and PHP, so whatever I'm doing wrong should be
a matter of syntax or simply a faulty build of perl...

Heres the scenario:

I have a program that instantiates child threads that perform some
measurements, and then has to fill in the results to a MySql database

Environment:
Running perl 5.8.0 and MySql 3.23.51 on a FreeBSD box

Problem:
It seems that I only can connect to the MySql DB from the main program, but
not from a thread.

When looking at the documantation on perldoc.com for DBI, this is what
stands out:
Threads and Thread Safety
Perl versions 5.004_50 and later include optional experimental support for
multiple threads on many platforms. If the DBI is built using a Perl that
has threads enabled then it will use a per-driver mutex to ensure that only
one thread is with a driver at any one time. Please note that support for
threads in Perl is still experimental and is known to have some significant
problems. It's use is not recommended.

BUT!! This shouldn't mean that I can't use SQL from a thread, it should only
mean that I can only access SQL from one thread at the time.. Right?

Well, anyways this is the errormessage I get when attempting to connect:

thread failed to start: Undefined subroutine &Carp::shortmess_heavy called
at /usr/local/lib/perl5/5.8.0/Carp.pm line 182.

using a line that works when i run it from the main thread:

$dbremote = DBI->connect("DBI:mysql:DBNAME;host=127.0.0.1", "USER", "PASS",
{ AutoCommit => 1 });



I also tried to establish one connection from the main thread, and then,
using the thread::shared package, share the handle, but this kills the
handle, because otherwise this approach might have worked instead.



I've also tried monitoring wether the number of connected DB clients matter,
but they don't I can connect 10 times from the main thread, but every time I
try from the thread, I get the errormessage..



My own personal theories revolve around the DBI-package possibly not beeing
compatible with the Interpreter Threads implemented in the new 5.8.0 perl,
or maybe the perl I have has been built wrong, in a way that allows the use
of threads, but "forgot" to tell the DBI- package about it or something
similar..
Avatar billede emmek Nybegynder
13. november 2002 - 10:17 #2
Det er muligt at connecte til mysql fra andre tråde end main, sagen var at jeg connectede og closede forbindelsen i en constructor, og selvom forbindelsen blev lukket igen, forhindrede det mig i at connecte fra en anden tråd.

MEN! Når laver jeg det i C++ istedet for perl.. Det stinker squ når det kommer til trådning...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester