Database supports three threading modes
Single-thread. In this mode, all mutexes was disabled and SQLite is unsafe to use with more than a single thread at once.
Multi-thread. In this mode, SQLite can being safely used by multiple threads provided that no single database connection is used Simultaneo usly in, or more threads.
Serialized. In serialized mode, SQLite can is safely used by multiple threads with no restriction.
Where serial mode is the default. Can be specified at compile time, at startup, at run time. The runtime overwrites the startup and overwrites the compile time when it starts.
Specify thread mode at startup
int sqlite3_open_v2( const char *filename, /* Database filename (UTF-8) */ sqlite3 **ppDb, /* OUT: SQLite db handle */ int flags, /* Flags */ const char *zVfs /* Name of VFS module to use */);
In this function, flags can specify the threading pattern, and other configurations can be specified.
The first part of the flags must be one of the following three:
1. sqlite_open_readonly
2. Sqlite_open_readwrite
3. Sqlite_open_readwrite | Sqlite_open_create
The second part can choose Sqlite_open_nomutex, Sqlite_open_fullmutex,sqlite_open_sharedcache,sqlite_open_privatecache or SQLITE_OPEN _uri.
- Sqlite_open_nomutex, select Multi-thread Threading Mode
- Sqlite_open_fullmutex, enter serialized threading mode.
SQLite and multithreading