[odb-users] Re Threading...

Andrew Cunningham odb at a-cunningham.com
Tue Feb 2 10:24:00 EST 2016


The "current transaction" ( an important concept to ODB) is local to the
thread  - it is kept in TLS -Thread Local Storage.  ODB assumes you will be
keeping a connection/transaction local to that thread, not sharing between
threads
So if you start a transaction in one thread, that transaction will not be
the "current" transaction in another thread.

In my case ( a single user SQLite database), I have one global
transaction/connection/session. When I start a thread , I "force" the
current transaction/connection/session for that new thread to the global
transaction/connection/session.



By the way, there is another link says:
>
> > Sharing a single instance of odb::database between multiple threads
> > is the recommended way. By default, it will use the connection pool
> > and re-use connections for different threads, as required.
>
> However, in our app, we share a single instance of odb::database between
> multiple threads, and use the connection pool.
>
> One thread is used for querying the database, the other thread is
> responsible for reading and writing database. According to the instruction,
> it should work.
>
> After debugging, I find that the transaction in another thread is taken as
> the current thread’s by mistake.
>
> I
> ****************************************
>


More information about the odb-users mailing list