SQLite.Net 线程安全吗?
我正在询问 .Net 实现 - System.Data.SQLite。 是否有以线程安全方式使用它的指南?
我知道 SQLite 本身可以编译 有或没有线程安全 - 但是System.Data.SQLite 是如何编译的?
I'm asking about the .Net implementation - System.Data.SQLite.
Are there guidelines to using it in a thread-safe manner?
I know SQLite itself can be compiled with or without thread safety - but how was System.Data.SQLite compiled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是线程安全的,因此您不能跨线程共享连接对象或类似对象。
自述文件中提到的线程错误修复与使用多个连接(即每个连接)到同一文件的多个线程以及可能产生何种问题或竞争条件有关。
例如,BEGIN 和 BEGIN IMMEDIATE 提到的线程竞争条件会产生不幸的影响,即使一个线程发出 BEGIN,随后发出 BEGIN 的另一个线程仍然可能在第一个线程之前拥有数据库。 这些类型的情况已得到解决。
但.NET 中的数据库连接(oracle、sqlite、ms sql server)不是线程安全的,周围的对象也不是。
It is not thread-safe, so you cannot share connection objects or similar across threads.
The thread bugfixes mentioned in the readme file has to do with multiple threads using multiple connections (ie. one each) to the same file, and what kind of problems or race conditions that might produce.
For instance, the thread race condition mentioned for BEGIN and BEGIN IMMEDIATE had the unfortunate effect that even though a thread issued a BEGIN, another thread that issued a BEGIN afterwards could still end up owning the database before the first one did. These types of situations have been fixed.
But database connections (oracle, sqlite, ms sql server) in .NET are not thread-safe, nor are the surrounding objects.