[odb-users] Re: ODB Crashed in a multi-threaded environment

Albert (Jinku) Gu albert.gu at ringcentral.com
Mon Feb 1 01:58:56 EST 2016


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.

Is there anything wrong?

For your information:
http://www.codesynthesis.com/pipermail/odb-users/2014-April/001821.html

Regards,
Albert

On Feb 1, 2016, at 9:45 AM, Albert (Jinku) Gu <albert.gu at ringcentral.com<mailto:albert.gu at ringcentral.com>> wrote:

Hi guys,

According to these two links:

  *   http://www.codesynthesis.com/pipermail/odb-users/2011-June/000124.html
  *   http://www.codesynthesis.com/pipermail/odb-users/2014-November/002242.html

We can know that odb::database is thread safe. With the connection pool, ODB will assign different odd::sqlite::connection instance to different threads.

In our app, there are two threads with a shared odd::sqlite::database instance, one thread is responsible for writing and reading, the other one is for reading only. Each of them will apply a connection before executing a transaction.

Sometimes, these two threads will access the same table, maybe the same row in database. At this time, odb will crash. And the exception message is “transaction already in progress in this thread”.

Am I doing something wrong? How can I resolve this issue?

Any help will be appreciated!

Regards,
Albert





More information about the odb-users mailing list