SQLite study notes (8)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.