Dan Kennedy <danielk1977-re5jqeeqqe8avxtiumw...@public.gmane.org> writes: > On Aug 17, 2010, at 1:48 AM, Nikolaus Rath wrote: > >> Hello, >> >> The script below fails with >> >> Deadlock detected when executing 'DELETE FROM foo WHERE id=2' >> >> What I think should be happening instead is this: >> >> - When executing statement 1, the main thread obtains a SHARED lock. > >> - When executing statement 2, the main thread briefly obtains an >> EXCLUSIVE lock. After statement 2 is executed, the EXCLUSIVE lock is >> released and the main thread continues to hold the SHARED lock >> (since >> statement 1 is still active) > > Quite correct.
Hmm. That's quite the opposite of what Igor said in his mail. Who is right now? >> - Thread 2 wants to get an EXCLUSIVE lock but it can't. So the busy >> handlers waits for the main thread to release it's lock. > > While waiting, thread 2 is holding a PENDING lock. Is there any way to convince thread 2 not to hold the pending lock while waiting? I tried to disable setbusytimeout() and do a manual wait as follows (in void execute()): rc=sqlite3_prepare_v2(db, s, -1, &stmt, NULL); assert(rc==SQLITE_OK); rc=sqlite3_step(stmt); if (rc == SQLITE_BUSY) { printf("Busy, retrying '%s'\n", s); rc=sqlite3_finalize(stmt); if(rc!=SQLITE_OK){ printf("Error finalizing '%s': %s\n", s, sqlite3_errmsg(db)); exit(1); } sleep(2); rc=sqlite3_prepare_v2(db, s, -1, &stmt, NULL); assert(rc==SQLITE_OK); rc=sqlite3_step(stmt); } but now I'm getting an error when finalizing the statement: Busy, retrying 'UPDATE foo SET id=42 WHERE id=5' Error finalizing 'UPDATE foo SET id=42 WHERE id=5': database is locked On the other hand, if I do not finalize the statement but just wait for 2 seconds before calling sqlite3_step() again, I get the same error as before (so I reasoned that to get rid of the PENDING lock I have to finalize the statement). Best, -Nikolaus -- »Time flies like an arrow, fruit flies like a Banana.« PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users