Recently, I am reading the source code of SQLite. I found that on OS level, SQLite use file lock to solve multi-processes problem and use VFS to solve multi-threads problem. But all of them might failed with racing and SQLite will return a SQLITE_BUSY result code to make it sleep-and-retry.
I get confused of this code. Why SQLite use lock-and-wait? For example, in the unixLock, we can use F_SETLKW instead of F_SETLK, so that code will return immediatly when file unlocked. We have not need to sleep-and-retry, which may waste our running time. So I think it might be a kind oftrick, but I don?t why SQLite do so. I already find out the www.sqlite.org, but it tells nothing about this. Does anybody know why SQLite design it so?