4 ms·
Can you elaborate/other (maybe lesser known?)/best practices related to this?
by atat7024 6y ago
Can you elaborate/other (maybe lesser known?)/best practices related to this?
- TeMPOraL 6y agoSQLite has good documentation. It covers multithreading and multi-process access too: https://www.sqlite.org/faq.html#q5 https://www.sqlite.org/faq.html#q5 https://www.sqlite.org/faq.html#q6 https://www.sqlite.org/faq.html#q6 https://www.sqlite.org/threadsafe.html https://www.sqlite.org/threadsafe.html TL;DR: - Multiple processes can read the database, but only one can write at any given time; this is enforced using FS locking. - For threading, there are three modes SQLite can operate in: single-threaded (unsafe for use in multiple threads), multi-threaded (safe to use in multiple threads, as long as each thread establishes its own connection) and serialized (do whatever you like, however you like). - The caveat for threading is that if SQLite was compiled with -DSQLITE_THREADSAFE=0 (i.e. single-threaded), then multi-threaded and serialized modes cannot be enabled at runtime, because locking code gets compiled out of the binary.