sqlite與多線程

來源:互聯網
上載者:User

標籤:

資料庫支援三種線程模式

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

  2. Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.

  3. Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.

其中串列模式是預設的。可以在編譯時間、啟動時、運行時指定。運行時會覆蓋啟動時,啟動時會覆蓋編譯時間。

啟動時指定線程模式
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 */);

在這個函數中,flags可以指定線程模式,還可以指定其他的配置。
flags的第一部分必須是下面三個之一:
1. SQLITE_OPEN_READONLY
2. SQLITE_OPEN_READWRITE
3. SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE

第二部分可以選擇 SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_FULLMUTEX,SQLITE_OPEN_SHAREDCACHE,SQLITE_OPEN_PRIVATECACHE或 SQLITE_OPEN_URI。

  • SQLITE_OPEN_NOMUTEX,選擇multi-thread線程模式
  • SQLITE_OPEN_FULLMUTEX,進入serialized線程模式。

sqlite與多線程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.