I\'m developing an application with SQLite as the database, and am having a little trouble understanding how to go about using it in multiple threads (none of the other Stac
Modern versions of SQLite has thread safety enabled by default. SQLITE_THREADSAFE compilation flag controls whether or not code is included in SQLite to enable it to operate safely in a multithreaded environment. Default value is SQLITE_THREADSAFE=1
. It means Serialized mode. In this mode:
In this mode (which is the default when SQLite is compiled with SQLITE_THREADSAFE=1) the SQLite library will itself serialize access to database connections and prepared statements so that the application is free to use the same database connection or the same prepared statement in different threads at the same time.
Use sqlite3_threadsafe()
function to check Sqlite library SQLITE_THREADSAFE
compilation flag.
Default library thread safety behavior can be changed via sqlite3_config()
. Use SQLITE_OPEN_NOMUTEX
and SQLITE_OPEN_FULLMUTEX
flags at sqlite3_open_v2()
to adjust the threading mode of individual database connections.