Do I need to block concurrent SQLite access for SELECT statements?
I am using FMDB to access standard iOS internal SQLite database, with one db connection shared by multiple threads.
To make it thread safe, I block access to the db one block of code at a time. Everything works well, although db access is a bit of a bottleneck now, obviously.
My question is, can I ease this a bit by allowing concurrent requests from multiple threads if they are all read-only SELECT operations?
I cannot find the answer anywhere.
source to share
You can have one object FMDatabase
per thread. You may need to write code to authenticate the free / busy terms and handle it correctly. For example, set one busyRetryTimeout
that is appropriate for your situation (for example, how long you want it to repeat in conflict situations). It is also graceful to handle if the timeout is running out and the database query fails.
Obviously using shared FMDatabaseQueue
is the easiest way to interact with databases from multiple threads. See Section Using FMDatabaseQueue and Thread Safety Section in FMDB README
.
source to share