SQLite Forum

set/get last_insert_rowid - To mutex or not mutex?
Login
OK, thanks Gunter.

So I guess it is a case of a *documented data-race* then.

Still, it doesn't make much sense to me. If you are not multi-threaded,  
then taking the mutex on writes is not necessary.

And if you are multi-threaded, not taking the mutex on read guarantees  
*garbage* in `db->lastRowid` in general. So might as well not take it on  
write either. `lastRowid` would need to be an atomic for that to be correct.

PS: I'm in a multi-threaded environment, but do enforce (as far as I know!)  
the *single-thread-per-connection* myself.