And those mutexes around statement usage apply the mutex based on the 
underlying connection, not the statement (which is irrelevant)?

---
Theory is when you know everything but nothing works.  Practice is when 
everything works but no one knows why.  Sometimes theory and practice are 
combined:  nothing works and no one knows why.


>-----Original Message-----
>From: [email protected] [mailto:sqlite-users-
>[email protected]] On Behalf Of Neo Anderson
>Sent: Sunday, 8 February, 2015 22:34
>To: General Discussion of SQLite Database
>Subject: Re: [sqlite] Multi-thread mode question
>
>> Does the application work if you configure SQLite to serialized mode?
>Yes. But I am confused why serialized mode works while multi-thread mode
>always cause crashes because I also wrap calls around statement handle.
>
>> even if you wrap the sqlite3_ calls... you'll need to wrap the entire
>> lifetime of the statment...
>Do I need to do this in serialized mode (suppose I use a single
>connection across multiple threads)?
>
>----------------------------------------
>> Date: Sun, 8 Feb 2015 03:31:46 -0800
>> From: [email protected]
>> To: [email protected]
>> Subject: Re: [sqlite] Multi-thread mode question
>>
>> it's better to use a connection per thread... the connection resource
>isn't
>> very big...
>> even if you wrap the sqlite3_ calls... you'll need to wrap the entire
>> lifetime of the statment... if you do a execute and then start stepping
>and
>> getting values while another thread starts another statement... that's
>3
>> individual locks, but it doesn't lock the context of the statement
>being
>> used... it will lead to bizarre crashes in the database; similar to
>> double-releasing memory or delayed reference of memory that has been
>> released.
>>
>> On Sun, Feb 8, 2015 at 3:00 AM, Dan Kennedy <[email protected]>
>wrote:
>>
>>> On 02/08/2015 04:30 PM, Neo Anderson wrote:
>>>
>>>> The doc says:
>>>>
>>>> Multi-thread.
>>>> In this mode, SQLite can be safely used by multiple threads provided
>that
>>>> no single database connection is used simultaneously in two or more
>>>> threads.
>>>>
>>>> I have a scenario that every sqlite3_calls around a single database
>>>> connection is protected by a recursive mutex, but I have very strange
>>>> runtime error in sqlite3.c and each time the error occurs at a
>different
>>>> place.
>>>>
>>>> Does this mean the following statement is true:
>>>>
>>>> In muti-thead mode, a single database connection cannot be shared
>among
>>>> threads even if any activity around the connection is protected by a
>mutex.
>>>>
>>>
>>> Not true.
>>>
>>> The only difference between multi-threaded and serialized mode is
>that,
>>> internally, every sqlite3_xxx() API call grabs a recursive mutex to
>prevent
>>> two threads from simultaneously accessing the database handle
>structure.
>>> i.e. the same thing your code is doing externally.
>>>
>>> Note that calls on statement handles (i.e. sqlite3_step(),
>>> sqlite3_column_text() etc.) count as calls on the database handle that
>>> created them. So you need to protect them with the same mutex.
>>>
>>> Does the application work if you configure SQLite to serialized mode?
>>>
>>> Dan.
>>>
>>>
>>>
>>> _______________________________________________
>>> sqlite-users mailing list
>>> [email protected]
>>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>>>
>> _______________________________________________
>> sqlite-users mailing list
>> [email protected]
>> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>_______________________________________________
>sqlite-users mailing list
>[email protected]
>http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to