来自多个线程的sqlite3的只读访问权限 [英] Read only access only for sqlite3 from multiple threads

查看:277
本文介绍了来自多个线程的sqlite3的只读访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://www.sqlite.org/threadsafe.html ,有三个使用sqlite时使用不同的线程模式:单线程多线程序列化.当配置为序列化多线程模式时,将使用互斥锁(取决于使用的模式是或多或少的),并且使用了单线程 >模式互斥量根本不使用.

According to http://www.sqlite.org/threadsafe.html there are three different threading modes when working with sqlite: single-threaded, multi-threaded and serialized. When configured to serialized and multi-threaded modes, mutexes are used (depending on the mode they are used more or less) and in single-threaded mode mutexes are not used at all.

假设数据库仅用于查询(只读访问),是否可以在仍然从其他线程访问数据库的同时使用单线程模式?还是需要保护全球资源?

Assuming that the database will only be used for queries (read-only access) is it possible to use the single-threaded mode while still accessing it from different threads? Or there are global resources that need to be protected?

此外,默认的ADO.NET适配器是否可以 System.Data.Sqlite 是否可以以相同的方式使用?

In addition, can the default ADO.NET adapter System.Data.Sqlite be used in the same manner?

推荐答案

SQLite库具有许多内部数据结构,即使对于只读数据库文件(缓存,编译后的语句,结果集等),其内部数据结构也会发生变化,因此您必须从不从多个线程访问单线程连接.

The SQLite library has many internal data structures that get changed even for a read-only database file (caches, compiled statements, result sets, etc.), so you must never access a single-threaded connection from multiple threads.

ADO.NET不做任何线程安全保证,因此 System.Data也不会. SQLite .

ADO.NET does not make any thread safety guarantees, so neither does System.Data.SQLite.

这篇关于来自多个线程的sqlite3的只读访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆