Hello All, I have been using SQLite for a couple of years but have never posted to this list before. I am sure my problem is common and am looking for ideas to solve it.
I have basically the same situation as this thread: ------------------------------------------- On Wed, Jan 26, 2011 at 10:56 AM, Ian Hardingham <ian at mode7games.com> wrote: > Hey guys. > > I am under the impression that there is no concurrent access to a single > SQLite DB. Ie if thread A is performing a query, and thread B trys to > query, it will block until thread A is finished, no matter the query. > > 1. Is this correct? > It is true if A and B are attempting to share the same database connection. Access to the database connection is protected by a mutex. > > 2. Are there any fairly general workarounds of any kind? > Use a separate database connection for each thread. Or better: Use processes instead of threads, as threads are evil. > > Thanks, > Ian -------------------------------------------------------- I have used SQLite extensively single-threaded with no problems (other than my own!). I am currently working on another project adding SQLite functionality to a multi-threaded environment. Here is my situation. Ubuntu 10.04 64-bit. Have used the SQLite3 library and compiled from source directly into the applicaition. Same results. Multi-threaded compile flag configuration kept as the default and forced with sqlite3_config() to SQLITE_CONFIG_MULTITHREAD with no error reported. Open is via SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE flags. I have tried this with and without shared cache. When I use the above configuration multi-threaded but using only one DB connection in which only one thread is accessing the DB at a time, it works fine for both read and write. I use OS read/write mutex in which all threads must obtain a write lock to get at the DB effectively forcing only one thread accessing the DB at one time. When I allow multiple readers with each thread using a different DB connection (open with the same flags) and each thread having exclusive use of its DB connection (no sharing of connections) and if more than one thread is reading the DB at the same time, the DB becomes locked for writing even when all the reads are finished. The DB is locked, not the OS mutex. There are no DB writes. How can the DB be locked for writes in this situation? I test this with the sqlite3 program and opening the database while the application is running and try to do an insert. I have been working for weeks on this and I feel there must be something simple I am overlooking. Thanks for any help. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users