I’d like to access a SQLite database from 2 different threads, thereby using 2 different connections to the database. Both threads will mainly perform reads from the DB and will write to the DB only occasionally. If I feel the odds are against both threads writing to the DB at the same time, should I feel safe that I should not have any issues in this scenario ?
Share
SQLite is threadsafe and, with recent versions, you can share a single connection among threads. That said, the SQLite FAQ states “Threads Are Evil” (I don’t think they mean this in the context of SQLite, but as a general statement).
SQLite has locking mechanisms so that even if a second instance tries to get a write lock on the database it will be queued until existing locks are finished, so even if both threads are writing SQLite should accommodate you. The FAQ suggests that it is generally not safe to use multiple connections from different processes on network file systems due to poorly implemented locking in the file system, but I don’t think that warning applies to your usage.