Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite's Serialized mode

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?

like image 299
ForeverLearning Avatar asked Oct 21 '11 13:10

ForeverLearning


1 Answers

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.

like image 191
Sebastian Krysmanski Avatar answered Sep 22 '22 14:09

Sebastian Krysmanski