Thread:
Many versions of SQLite support multithreading.
Shared cache model:
Allows multiple connections in a process to use a common page cache. There are many cases for Embedded servers.
Thread → server → con → page cache → database.
In the shared cache mode, threads rely on server threads to help manage database connections. A thread uses a communication mechanism to send SQL statements to the server. The server executes the SQL statements through connections allocated by the thread and returns results. The thread can continue to issue commands to control its own transactions, but the actual connection exists in other threads and there are other threads for management.
Connections in the shared cache mode use different concurrency models and isolation levels. Pay attention to the changes to the same-family connection.
Read uncommitted isolation level:
Indicates read_uncommited. The connection is the isolation level of the uncommitted read.
Unlock notification:
Functions included in the new version of SQLite: sqlite3_unlock_notify ();
Statement:
Int sqlite3_unlock_policy (
Sqlite3 * pblocked,/* waiting connection */
Void (* xnotify) (void ** aparg, int NARG)/* callback function to be triggered */
Void * ppolicyarg/* parameter passed to xnotify */
);
If the shared lock is not obtained because of code competition, sqlite_locked will be returned. At this time, the sqlite3_unlock_y y () function is called and the callback function xnotify is registered on the blocked connection (the first parameter;
The callback function can have any parameters.
A connection with a blocking lock will trigger the xnotify callback as part of the sqlite3_step () or sqlite3_close () of the transaction. When multiple threads call sqlite3_unlock_notify (), the transaction may have been completed. The callback function is initialized from sqlite3_unlock_policy. Each blocked connection has only one registration and unlock/notification callback function. It cannot be re-imported, and other functions should be called in the callback function. When using drop, errors may occur on a business trip.
Thread and memory management:
Functions associated with memory management (specifying the heap size and limiting the stack ):
Void sqlite3_soft_heap_limit (int n); set the soft heap to n Bytes. If the memory used exceeds N, the next function sqlite3_release_memory (int n) is called to return the actual number of released bytes.
Int sqlite3_release_memory (int n );
By default, these functions are null unless the pre-processing command sqlite_enable_memory_managenent is started during SQLite compilation.