On 8 Apr 2014, at 3:20pm, David Brown <david.br...@bisimulations.com> wrote:
> It's my understanding that any number of reads can be going on > simultaneously (from other threads even) but ONLY ONE thread can write at a > time. Is this correct? Right. > Also, how would one handle multiple threads reading and writing > simultaneously if this is not the case? While any connection is reading or writing to the database, the database is locked against anything else trying to write to it. (This is simplified but gives you an idea of what it does.) When thinking about this it's important to remember that all reads and writes involve transactions, whether you declared them or not. > I have a database that is being written to once a second and another thread > that tries to read ONCE from the same table being written to and write to > another separate table (this is when I would experience a crash). > > I fixed the crash by handling an exception for "database locked" which > leads me to believe it was the second thread trying to write at the same > time that was the problem. Ensure that you have set a timeout value for each connection accessing that database. Without this, SQLite will always interpret a clash as being serious enough to report an error. By default no timeout is set. <https://sqlite.org/c3ref/busy_timeout.html> <http://www.sqlite.org/pragma.html#pragma_busy_timeout> A timeout of 5 seconds (or a few minutes) clears up most of the problems like the ones you described. You shouldn't have to write your own code to do it. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users