How to use SQLite in a multi-threaded application?

前端 未结 7 948
情书的邮戳
情书的邮戳 2020-11-28 02:43

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

相关标签:
7条回答
  • 2020-11-28 03:23

    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.

    0 讨论(0)
提交回复
热议问题