From: Georgios P. <pet...@ya...> - 2016-09-02 10:37:02
|
On 2/9/2016 12:51, to...@tu... wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Fri, Sep 02, 2016 at 12:20:27PM +0300, Georgios Petasis wrote: >> Hi all, >> >> I want to use a mysql database from multiple threads. What I do right >> now, is to load the packages from multiple threads, and use the database >> as I would from a single thread. >> >> The problem is that I am getting errors when beginning transactions. The >> errors are about locks, timetouts, etc. > [...] > > Sorry, not really specific to tdbc, but from what I know about other > similar interfaces: the database connection has a state, and this > state doesn't expect to be "seen" by independent entities (be it threads > or whatever). > > Possible approaches: > > (1) Set up a separate connection handle for each thread. I am creating a separate connection for each thread. Each thread has its own connection. I am at the tcl level, using the thread package. > > (2) Use some cunning scheme which somehow manages this > state, creating an illusion of a private handle > per client (instance). Traditionally this is called > "connection pooling" and implemented by having one > thread handling the mess on behalf of the others. > > That said, perhaps ODBC is smarter than I think and pretends to do > that for you: then that'd be a bug :-) > > (Sorry if you knew all of this. Perhaps I just failed to gather that > from your question). Since I have a new connection per thread, I was expecting that begin transaction/commit will be particular to each thread. However, they seem to interfere, and mysql client gets confused. Or I am using tdbc::mysql the wrong way. Is there any tdbc example, that accesses (any) database with threads, and has transactions? Thank you for your answer, George |