Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SQLite optimization



On Aug 28, 2006, at 3:48 AM, Mark Gilbert wrote:
My app accesses the same SQlite database from several threads, and in order to accommodate this I currently open and close the database on each access, and the various threads will wait when the database is busy on another thread.

First, I'd recommend asking SQLite-specific questions on the relevant SQLite mailing list(s) at <http://www.sqlite.org/> -- that's where you'll find the experts.


<http://www.sqlite.org/faq.html#q8> says:

(8) Is SQLite threadsafe?

Yes. Sometimes. In order to be thread-safe, SQLite must be compiled with the THREADSAFE preprocessor macro set to 1. In the default distribution, the windows binaries are compiled to be threadsafe but the linux binaries are not. If you want to change this, you'll have to recompile.

"Threadsafe" in the previous paragraph means that two or more threads can run SQLite at the same time on different "sqlite3" structures returned from separate calls to sqlite3_open(). It is never safe to use the same sqlite3 structure pointer in two or more threads.

So the relevant question for this list is, "Was SQLite compiled threadsafe?" Taking a look at <http://www.opensource.apple.com/ darwinsource/10.4.7.ppc/SQLite-28/Makefile> shows "--enable- threadsafe" is used in the configuration options -- so I believe it is.


Therefore, you don't need to repeatedly call open and close -- you just need to have one open per thread and SQLite will take care of the rest of the synchronization.

- Kevin

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >SQLite optimization (From: Mark Gilbert <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.