SQLite Forum

Random crash doing SELECT
Login
> The SQLite documentation is kind of obscure when comes to concurrent usage.

In what what way?  

It is quite clear that a connection is serially entrant on multiple threads, and that you cannot enter sqlite3 using the same connection on separate threads simultaneously.  

It is also clear that in order to ensure these requirements are followed there is a specific configuration option for your use to help **YOU** comply with the requirements.  Not you, God (she's black you know), nor anyone else can CHANGE the requirements, but **you** can change how **YOU** will comply with them.

Method 1:  USE ONLY A SINGLE THREAD

Configure SQLite3 for "single thread" operation.  This removes all protections and capability to use SQLite3 with multiple threads by removing or disabling ALL shared data MUTEXes.

Method 2:  USE MULTIPLE THREADS, BELTS, and SUSPENDERS

This is the default configuration of SQLite3.  You are permitted to use SQLite3 with multiple threads.  The requirements are unchanged.  SQLite3 will **ENSURE** that **YOU** behave in accordance with the requirements for serial entry by actively managing a set of MUTEX semaphores to **PREVENT YOU** from violating the requirements.  This is the default mode.  SERIALIZED.  FULLMUTEX.

Method 3:  USE MULTIPLE THREADS WITHOUT BELT AND SUSPENDERS

Configure SQLite3 for MULTITHREAD operation or open a connection with NOMUTEX.  **YOU** must ensure that you comply with the requirements or all hell will break loose (which may entail a wide range of behaviours ranging from merely strange corruption issues to crashes all the way up to and including the destruction of the multiverse).

Method 1 is the default.  It will **ALWAYS** work properly.  You may save a few nanoseconds per entry into the SQLite3 code by specifying one of the other methods **IF AND ONLY IF THEY APPLY**.  Under no circumstance whatsoever may **YOU** violate the requirements.

Basically, if something does not work properly when using some configuration **OTHER THAN** the default SERIALIZED / FULLMUTEX, but works properly when using the default configuration, that means that **YOU** are not complying with the entry requirements **YOU** have stated you will comply with.