SQLite and multithreading

Source: Internet
Author: User
Tags sqlite sqlite db

Database supports three threading modes

  1. Single-thread. In this mode, all mutexes was disabled and SQLite is unsafe to use with more than a single thread at once.

  2. 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.

  3. 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

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.