Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3_prepare_v2 exc_bad_access

I'm getting exc_bad_access when using multiple readers for sqlite on iOS. WAL is enabled on the database and sqlite3_threadsafety returns 2 so this shouldn't be a problem.

The code I'm using works fine for 100k+ users most of the time, but there are certain multithreading race conditions that cause sqlite3_prepare_v2 to have exc_bad_access. Basically when I spawn two threads to do a bunch of reads it crashes.

With WAL and threadsafe sqlite, multiple threads shouldn't be a problem but can't figure out what's causing this exc_bad_access.

Thanks in advance.

like image 493
VTS12 Avatar asked Nov 08 '12 14:11

VTS12


1 Answers

In that sense SQLite3 is not thread safe 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.

like image 157
Raviprakash Avatar answered Sep 28 '22 10:09

Raviprakash