On Jan 15, 2009, at 6:07 AM, John Belli wrote:
> Assuming I've decided to use evil threads, and am opening a new
> connection in each thread, does it matter whether I use multithreaded
> (-DSQLITE_THREADSAFE=2) or serialized (-DSQLITE_THREADSAFE=1)? Any
> idea if one is faster than the other? I am using SQLite on Win32 and
> WinCE, and I'll be using shared caching
> (sqlite3_enable_shared_cache(TRUE)).
In serialized mode, each database handle (sqlite3*) has an internal
mutex. Each time any API call is made on that database handle, the
mutex is obtained, the work of the API call is done, and the mutex
is released. Making an API call on a statement object prepared using
the database handle counts as making an API call on the database handle
itself for the purposes of this mutex.
Therefore, in serialized mode, SQLite database and statement handles
are threadsafe objects. You can make simultaneous calls on database
or statement handles from multiple evilthreads if you so desire.
In multi-thread mode, this database handle mutex is omitted. So things
run slightly faster because there is one less mutex grab each time
an API call is made. But if you make simultaneous calls on a single
database handle from multiple evilthreads, sqlite will crash or
malfunction.
In your situation, where you are promising that a database handle will
only ever be used by the evilthread that created it, you could probably
get away with multi-thread mode. You would have no more or less
concurrency as when using serialized mode though. Possibly a tiny
performance improvement because you avoid a few mutex grabs though.
Don't forget that for thread-safety purposes, accessing a statement
handle counts as accessing the database handle that was used to
prepare it.
> JAB
> --
> John A. Belli
> Software Engineer
> Refrigerated Transport Electronics, Inc.
> http://www.rtelectronics.com
>
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users