On SQLITE_BUSY, wait a random amount of time

If all contending processes wait a fixed amount of time (100 ms),
there is a good probability that they'll just collide again.
This commit is contained in:
Eelco Dolstra 2012-12-11 11:49:42 +01:00
parent e087bfef5f
commit 772778c0ec
2 changed files with 7 additions and 1 deletions

View file

@ -48,7 +48,7 @@ static void throwSQLiteError(sqlite3 * db, const format & f)
#if HAVE_NANOSLEEP
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = 100 * 1000 * 1000; /* 0.1s */
t.tv_nsec = (random() % 100) * 1000 * 1000; /* <= 0.1s */
nanosleep(&t, 0);
#else
sleep(1);