在 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/