I\'m using an SQLite database in my iPhone app. At startup, there are some database actions that I want to perform in a separate thread. (I\'m doing this mainly to minimize
That error message maps to SQLITE_MISUSE (the source code is available at http://www.sqlite.org).
See http://www.sqlite.org/faq.html#q6 for limitations on using an sqlite3 * database handle from more than one thread. Effectively, you are allowed to reuse a database handle and statements across threads but one thread must be completely done accessing the database before the other thread starts (i.e. overlapping access is not safe). That sounds like what's happening for you and is consistent with the SQLITE_MISUSE error code.
If you need to access the same database from more than one thread, I recommend instead opening the database separately from each thread and setting a timeout using sqlite3_busy_timeout(). Sqlite will then handle contention for you, blocking for a short time in one thread if the other thread is writing data while still allowing simultaneous reads.
Your best bet is to use GCD (Grand Central Dispatch) queues to prevent simultaneous access to the sqlite database.
Using any form of locking (including file locking that would be used by multiple database instances) may cause busy waiting which is wasteful.
See my answer to a similar question.