> And that explanation along with why one would want to use each mode would be
> quite helpful to the community I would think.

>From examining the source I see that it the serialization is via the mutex 
>attached to the database connection.  Serialization of statements is achieved 
>by reference to the connection from which is was generated, so the statement 
>"SQLite can be used in a multithreaded program so long as no two threads 
>attempt to use the same database connection *or any statement prepared on that 
>connection*, at the same time" should have the part between the asterisks 
>added to make it perfectly clear which data structure limits multiple entrants.

As to why one would want to use each mode is pretty simple:

THREADSAFE=0 or single-threaded.  If you only have one thread on which all 
database operations will be performed (though you may have additional threads 
doing "other things", just not calling into SQLite).

THREADSAFE=2 or Serialized.  If you have multiple threads calling into SQLite 
*and* you do not want to manage synchronization, then this is the mode you 
should use.  It is also the default.  

THREADSAFE=1 or Free Threading.  You have designed your software so that it is 
impossible for calls into the engine to be made from more than 1 thread per 
database connection.  For example, you store your pointers to the database 
connection and any prepared statements in thread-local storage.

The only advantage of THREADSAFE=1 over THREADSAFE=2 is that you do not incur 
the cost of testing/acquiring/releasing the connection mutex around SQLite 
calls.

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to