Re: [sqlite] Thread-safety and sqlite3_stmt objects

2009-03-06 Thread Shawn Wilsher
On Fri, Mar 6, 2009 at 9:26 PM, Dan  wrote:

> Why do you want to use a single sqlite3_stmt* from multiple threads
> at the same time?

Really the only thing I need to access is sqlite3_sql to copy the statement
to another thread.

We have an asynchronous API that we expose to add-ons and core code in
Mozilla.  Right now, when a consumer calls executeAsync on a statement, we
make a new copy of the statement, transfer the bindings, and pass the new
one to the thread that executes the statement.  However, profiling shows
that creating a statement can often be an expensive operation.  I'm looking
at just giving the second thread the statement, and if the original thread
needs the statement again, I want to clone it off of the original.

Note: I'm leaving out some details here that probably aren't important.

Cheers,

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


Re: [sqlite] Thread-safety and sqlite3_stmt objects

2009-03-06 Thread Dan

On Mar 7, 2009, at 1:31 AM, Shawn Wilsher wrote:

> Hey all,
>
> I've been looking online for a bit trying to establish what  
> protections, if
> any, are associated with sqlite3_stmt objects.  It's clearly  
> documented that
> sqlite3 objects' access is serialized across threads, but I cannot  
> find
> anything about sqlite3_stmt.  I don't actually care either way, but if
> SQLite protects it internally, I don't want to add additional  
> overhead by
> protecting it myself.

Each database connection (sqlite3) has associated with it a single
mutex. Many of the operations on an sqlite3_step* object are protected
internally by this mutex (i.e. sqlite3_step()). But some are not,
especially the data access functions like sqlite3_data_count() etc.

Accessing values using the sqlite3_column_XXX() API is nearly  
threadsafe.
If some other thread calls sqlite3_step() to advance the statement while
the first thread is calling sqlite3_column_XXX(), then you could  
conceivably
get a problem. But multiple threads using the sqlite3_column_XXX()  
functions
is safe.

So I suppose the only correct answer is "no, they are not threadsafe
objects".

Why do you want to use a single sqlite3_stmt* from multiple threads
at the same time?

Dan.



> Could someone please clarify this (and maybe add some documentation)?
>
> Cheers,
>
> Shawn Wilsher
> Mozilla Developer
> ___
> 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


[sqlite] Thread-safety and sqlite3_stmt objects

2009-03-06 Thread Shawn Wilsher
Hey all,

I've been looking online for a bit trying to establish what protections, if
any, are associated with sqlite3_stmt objects.  It's clearly documented that
sqlite3 objects' access is serialized across threads, but I cannot find
anything about sqlite3_stmt.  I don't actually care either way, but if
SQLite protects it internally, I don't want to add additional overhead by
protecting it myself.

Could someone please clarify this (and maybe add some documentation)?

Cheers,

Shawn Wilsher
Mozilla Developer
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users