SQLite Forum

Multithreading support
Login

Multithreading support

(1) By oneeyeman on 2020-09-19 15:45:32 [link] [source]

Hi, In my application I use thread to query SQLite DB and I also query DB from the main application.

Should I turn on MT support in SQLite?

Thank you.

(2) By Keith Medcalf (kmedcalf) on 2020-09-19 22:43:36 in reply to 1 [source]

Multithread support in SQLite3 is turned on by default as SERIALIZED. That is, the library itself will prevent multiple-simultaneous entry on the same connection.

You can alter this if you really want to either though the sqlite3_config API or compilation options, but you should understand the implications of doing so.

https://sqlite.org/c3ref/config.html
https://sqlite.org/threadsafe.html

The option SERIALIZED (the default) means that SQLite3 itself will enforce the entrance requirements in order to avoid having programming errors cause explosions.

The option MULTITHREAD means that YOU THE PROGRAMMER are responsible for ensuring that entrance requirements are met and that SQLite3 will not spend a few extra nanoseconds per call enforcing the single entrance requirements per connection.

The option SINGLETHREAD means that calls into the SQLite3 library will be made on only one thread and that all simultaneous access control will be disabled. (You may still use multiple threads however you are now restricted to being serially single entrant for the entire library -- across all connections, not just per connection).

If you change the default from SERIALIZED to something else and fail to comply with the requirements then explosions and data loss may ensue for which the risk is entirely on you.

(3) By oneeyeman on 2020-09-19 23:36:35 in reply to 2 [link] [source]

@KeithMedcalf, Thank you for clarification!