[odb-users] RE: SQLITE unable to open db multiple threads

Sum, Eric B eric.b.sum at lmco.com
Mon Aug 6 09:25:26 EDT 2012


Sorry, one more follow-up question.

The odb manual states that by default, a sqlite connection_pool_factory is used, which behind the scenes uses the shared_cache/unlock_notify mechanism.  From reading about the shared_cache/unlock_notify mechanism it seems that "The sqlite3_unlock_notify()<http://sqlite.org/c3ref/unlock_notify.html> interface is designed for use in systems that have a separate thread assigned to each database connection<http://sqlite.org/c3ref/sqlite3.html>"  and the shared_cache mechanism allows the same cache to be shared across the entire process that contains all of its threads.  How do I create a database connection for each individual separate thread as it seems the intended use is?

1.        I tried explicitly calling connection_ptr c(db.connection())  in each thread on the existing db object created in the main function that was passed to each thread.

2.       I tried passing the existing db object to each thread, which I suppose does not create a new connection and uses the existing one across multiple threads.

3.       I tried called the sqlite db constructor in each thread to open the existing database created in the main function in READWRITE mode, which I assume creates a connection in each thread to use.

None of these seemed to work.  Any help or insight on this is much appreciated.

Thanks again,
Eric

From: Sum, Eric B
Sent: Monday, August 06, 2012 9:09 AM
To: 'odb-users at codesynthesis.com'
Subject: SQLITE unable to open db multiple threads

Hi,

I am persisting objects into a sqlite database from multiple threads.  However, I am getting odd results caught with odb exceptions.  I get sqlite error 14: unable to open database multiple times throughout the execution of my program, and only a fraction of the objects persisted are present in the database.  I assume I am getting this error because one of the threads is unable to establish a connection to the database.  I am aware that you are unable to do concurrent writes to the sqlite database due to its exclusive locking mechanism, but I thought that there would be some scheduling/blocking scheme used inherently by odb to schedule the order of the persists from the different threads.    How do I fix this?  Any ideas on why I am getting this error?

Thanks,
Eric


More information about the odb-users mailing list