Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you elaborate/other (maybe lesser known?)/best practices related to this?


SQLite has good documentation. It covers multithreading and multi-process access too:

https://www.sqlite.org/faq.html#q5

https://www.sqlite.org/faq.html#q6

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.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: