objective-c - sqlite3_prepare_v2 exc_bad_access

标签 objective-c ios database multithreading sqlite

在 iOS 上为 sqlite 使用多个读取器时,我遇到了 exc_bad_access。 WAL 在数据库上启用并且 sqlite3_threadsafety 返回 2,所以这应该不是问题。

我使用的代码大部分时间都适用于 100k+ 用户,但存在某些多线程竞争条件导致 sqlite3_prepare_v2 具有 exc_bad_access。基本上,当我生成两个线程来进行大量读取时,它会崩溃。

使用 WAL 和线程安全的 sqlite,多线程应该不是问题,但无法弄清楚是什么导致了这个 exc_bad_access。

提前致谢。

最佳答案

从这个意义上说,SQLite3 不是线程安全的 refer SQLite document

By "threadsafe" we mean that you can use different SQLite database connections in different threads at the same time. It has never been safe to use the same database connection simultaneously in multiple threads. If you use the sqlite3_prepare() API to create prepared statements, each prepared statement is considered to be a part of the database connection from which it was derived. So you cannot run two prepared statements originating from the same database connection in different threads at the same time.

关于objective-c - sqlite3_prepare_v2 exc_bad_access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13291036/

相关文章:

ios - 在 iOS 应用程序中使用预构建的 sqlite 数据库

objective-c - iOS5 ARC 从后台选择器安排 NSTimers 是否安全?

java - jdbc:我什么时候可以关闭什么

database - 存储银行交易的最佳数据库是什么?

objective-c - Mac 应用程序中的数据库选项

ios - AES128 在 iOS 7 上截断解密文本,在 iOS 8 上没有问题

jquery - Xcode 4.5.1、Cordova 2.2、jquery 移动

android - 检测桌面或设备上播放的内容?

ios - 带有用于关闭键盘垫的 uibar 的文本字段

mysql - 为什么当用户没有提交时 MySQL 查询返回 null?