On Wednesday, 16 August, 2017 00:11, Gwendal Roué <gwendal.r...@gmail.com> 
wrote:
>> Le 15 août 2017 à 08:44, Clemens Ladisch <clem...@ladisch.de> a écrit :

>> sanhua.zh wrote:

>>> All 1. 2. 3. steps are run sequentially, which means that the step 2
>>> runs after step 1 finished and step 3 runs after step 2 finished
>>> theoretically .
>>> Also, I can make sure the memory order between threads.
>>>
>>> Then, is it a safe way to use sqlite connection ?

>> Yes.

>> Multi-threading problems are caused by multiple threads accessing the
>> same data at the same time.  If code in multiple threads is serialized,
>> it is, for practical purpose, identical to single-threaded code.

>Serialized accesses from multiple threads is OK when the connection
>is in the "Multi-thread" or "Serialized" threading modes, but not in
>the "Single-thread" threading mode.

>Have a look at https://www.sqlite.org/threadsafe.html for detailed
>information.

Basically, the restriction is on simultaneous entry from multiple threads to 
objects on the same connection (that is, simultaneous calls to 
prepare/bind/step/colun/reset/finalize from multiple threads at the same time). 
 The default is to SERIALIZE any such accesses to ensure that the 
single-entrance requirement for each connection is enforced through built-in 
mutexes.

Setting "multithreaded" mode disables these checks in the SQLite3 library and 
it is up to the application level code to ensure the single-entrance per 
connection is enforced at the application level.  If the application makes a 
"mistake" and violates the rules then corruption and not nice consequences will 
ensue.  However, since the SQLite3 core is no longer passing through a mutex on 
each entry, the code runs slightly faster.

Setting "single-threaded" mode disables all mutexes in the library and is 
intended for use when the code is entirely single threaded.  Since there is no 
protection at all (even for the VFS layer) if you perform any kind of 
multiple-entrance nasty consequences may ensue.

Generally speaking if you leave the default "serialized" mode, then you are 
protected against accidental re-entrancy application errors on multiple threads 
at a price penalty for the extra safety.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.




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

Reply via email to