Do you have any transactions that look like:

BEGIN
SELECT
INSERT/DELETE/UPDATE
COMMIT

If you do, you may have multiple threads trying to escalate from a
SHARED to a RESERVED lock as described here:
http://sqlite.org/capi3ref.html#sqlite3_busy_handler

It's important that if you have multithreaded access and a strategy that
involves either retrying or waiting on SQLITE_BUSY that you specify at
the beginning of write transactions that the transaction requires a
higher level lock.  I do this using "BEGIN IMMEDIATE".  

The thread currently on this list with subject
"[sqlite] BEGIN and Backup [was [sqlite] Problems with multiple
threads?]"
Discusses a similar issue.

Pat

-----Original Message-----
From: Jiri Hajek [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 07, 2006 9:26 AM
To: sqlite-users@sqlite.org
Subject: RE: [sqlite] Problems with multiple threads?

Thanks for an additional explanation, I used sqlite3_get_autocommit()
for
debugging and it helped me to find out that it really was my fault.
There
was an incorrect processing after COMMIT returned SQLITE_BUSY. So sorry
for
this.

However, right after fixing this, I found another problem. It certainly
can
be my fault, but I don't see how could it be: If I don't use
transactions,
multiple threads seem to proceed well, but then right after I add BEGIN
and
COMMIT to some place, all threads lock eventually. I debugged it and
found
that _all_ threads accessing SQLite are in a loop waiting for an action
to
proceed and all of them keep getting SQLITE_BUSY result. I wonder, can
it be
somehow my fault, or is it some kind of a dead-lock in SQLite?

In the simpliest form it takes only two threads to reproduce and the
problem
looks like:

Thread 1:

BEGIN TRANSACTION            <-- proceeded
INSERT INTO ...                      <-- Processing stops here, waiting
in a
loop, Sqlite3_step() infinitely returns SQLITE_BUSY
COMMIT


Thread 2:

  // no explicit transaction start here
DELETE FROM ...                   <-- Processing stops here, waiting in
a
loop, Sqlite3_step() infinitely returns SQLITE_BUSY


Thread 2 can also look like this in order to reproduce the problem
(situation in Thread 1 remains the same):

BEGIN TRANSACTION            <-- proceeded
DELETE FROM ...                  <-- proceeded 
COMMIT                                 <-- Processing stops here,
waiting in
a loop, Sqlite3_step() infinitely returns SQLITE_BUSY

No other thread calls any SQLite function.

Do you have any idea what could be wrong?

Thanks,
Jiri


Reply via email to