sqlite3 multithreading in objective c sqlite3 multithreading in objective c sqlite sqlite

sqlite3 multithreading in objective c


I think you're pursuing the wrong approach. SQLite isn't reliably threadsafe no matter how you compile it — see the FAQ. Even if SQLite is compiled for thread safety, the same database may not be used from multiple threads if any transactions are pending or any statements remain unfinalised.

The recommendations above to use Grand Central Dispatch to funnel all SQLite accesses into a serial dispatch queue are the right way to proceed in my opinion, though I'd be more likely to recommend that you create your own queue rather than use the main queue for the simple reason that you can reliably dispatch_sync when you want to wait on a result.


You can add all of your access statements to, therefore you are always on the main thread when access the sqlite store.

dispatch_async(dispatch_get_main_queue(), ^ {    //code goes here});