In the docs here: http://www.sqlite.org/threadsafe.html
For serialized mode it says: "In serialized mode, SQLite can be safely used by multiple threads with no restriction."
I want to make sure I understand the guarantee presented there. If a single database connection is opened using the "SQLITE_OPEN_FULLMUTEX" flag and two threads simultaneously try to call sqlite3_exec at the exact same instant, does Sqlite automatically serialize the calls?
The answer is yes. sqlite3_exec()
will grab a mutex when the function is entered and releases the mutext once the function is left. Only one thread can own the mutex at any given time, so only one thread can execute sqlite3_exec()
at any given time. If two threads try to execute sqlite3_exec()
at the same time, one will wait for the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With