Alex Rivera | Logout

Sqlite's Serialized mode

Asked 2011-10-21T13:23:49.117
14

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?

Edit
Report

1 Answer

10

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.

answered 2012-10-15T09:21:01.213

Your Answer