简体   繁体   English

Sqlite中的多线程

[英]Multithreading in Sqlite

I am using System.data.sqlite for connecting to Sqlite Database, as per the Sqlite documentation , users can enable multithreading by using SQLITE_OPEN_NOMUTEX flag as part of connection string. 我使用System.data.sqlite连接到Sqlite数据库,根据Sqlite文档 ,用户可以通过使用SQLITE_OPEN_NOMUTEX标志作为连接字符串的一部分来启用多线程。 But I couldn't find any key in the connection string which accepts flag. 但我找不到接受标志的连接字符串中的任何键。 Is it enabled by default? 它是默认启用的吗? if not how can I do this? 如果不是我怎么能这样做?

The threading mode is determined by compile time, startup or runtime options. 线程模式由编译时,启动或运行时选项决定。 More details here: 更多细节在这里:

http://www.sqlite.org/threadsafe.html http://www.sqlite.org/threadsafe.html

The docs say serialized is the default which means you're fine to use from multiple threads - it will guard you. 文档说序列化是默认的,这意味着你可以从多个线程中使用它 - 它会保护你。 If you want more parallelism, you can use multi-threaded mode. 如果需要更多并行性,可以使用多线程模式。

If you use it in multi-threaded mode, make sure that calls are synchronized for a given connection. 如果在多线程模式下使用它,请确保为给定连接同步调用。 If you want parallel work, use multiple connections and guard the connection. 如果要进行并行工作,请使用多个连接并保护连接。

The API itself hints at this by taking the db object (connection) as an argument to many functions that you call sequentially. API本身通过将db对象(连接)作为参数连接到您按顺序调用的许多函数来暗示这一点。 For example, look at these functions that you call to get an error: 例如,查看您调用以获取错误的这些函数:

int sqlite3_errcode(sqlite3 *db); 
const char *sqlite3_errmsg(sqlite3*);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM