用于具有多个数据库的单线程模式的sqlite多线程

时间:2013-06-15 15:36:17

标签: sqlite

Sqlite文档说明多线程

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.

我对1(单线程模式)有疑问。这是否说

  1. 不允许在两个帖子中使用sqlite3_open。

  2. 不允许使用sqlite3_open在两个中打开同一个数据库 thread.But使用sqlite3_open在两个线程中打开两个不同的数据库即可。

1 个答案:

答案 0 :(得分:2)

选项1.如果您需要选项2,则需要使用多线程模式,正如文本所述。在单线程模式下,sqlite函数的全局状态将不受保护,并且在多个线程中同时使用它们将是一个问题。

使用多线程模式,您可以在同一个应用程序中的多个线程中使用sqlite,但是您可能不会同时在线程之间共享一个连接。