[yunqa.de] Re: Thread Safety of Disqlite 3 Pro

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Sun, 01 Apr 2012 21:21:23 +0200

On 31.03.2012 20:50, Rémi MEVAERE wrote:

> I would like to have information about Thread Safety in Disqlite. 
> I searched in Help and I see that Disqlite 3 is thread Safety
> (sqlite3_threadsafe() return 1).

Correct. DISQLite3 is compiled with thread safety.

> The problem is if I have 2 Applications with ten threads each one. Could
> I Open, Prepare, Check on the SAME database without problem and without
> precaution ?

Absolutely. Be prepared, however, that only a single thread can write to a 
database at a given time. And remember to synchronize your threads as usual 
where they interact with each other or the main application.

> what is the goal of the DISQLite3_Busy_Timeout Demo ? It strange, i was
> conviced that it was a workaround to have a thread safe access to the
> database.

The DISQLite3_Busy_Timeout demo project is a simple framework to experiment 
with different sqlite3_busy_timeout() settings.

sqlite3_busy_timeout() sets the time a DISQLite3 operation will wait on a 
locked table before it returns SQLITE_BUSY. If you set the demo's 
WRITE_BUSY_TIMEOUT = 30, for example, the insert will time out.

This is important if a database connection or thread wants to write to the 
database while others are reading from it. If the readers take too long, the 
writer might fail. In this case, a prolonged busy sqlite3_busy_timeout() might 
help to wait just long enough to find the empty slot.

Thread safety is not effected by sqlite3_busy_timeout(). And since DISQLite3 
has no limit of the number of concurrent readers, it does not matter at all as 
long as you are only reading from the database.

DISQLite3's database locking is discussed in detail in

DISQLite3.chm -> SQLite3 Documentation -> Atomic Commit -> Locking & Concurrency

Delphi Inspiration mailing list

Other related posts: