Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read only access only for sqlite3 from multiple threads

According to http://www.sqlite.org/threadsafe.html there are three different threading modes when working with sqlite: single-threaded, multi-threaded and serialized. When configured to serialized and multi-threaded modes, mutexes are used (depending on the mode they are used more or less) and in single-threaded mode mutexes are not used at all.

Assuming that the database will only be used for queries (read-only access) is it possible to use the single-threaded mode while still accessing it from different threads? Or there are global resources that need to be protected?

In addition, can the default ADO.NET adapter System.Data.Sqlite be used in the same manner?

like image 388
buskila Avatar asked Dec 17 '12 10:12

buskila


1 Answers

The SQLite library has many internal data structures that get changed even for a read-only database file (caches, compiled statements, result sets, etc.), so you must never access a single-threaded connection from multiple threads.

ADO.NET does not make any thread safety guarantees, so neither does System.Data.SQLite.

like image 59
CL. Avatar answered Nov 15 '22 08:11

CL.