guruz
guruz

Reputation: 1614

Which threading mode is Sqlite for iOS compiled in?

The page http://www.sqlite.org/threadsafe.html mentions:

Which mode is the sqlite that is integrated in iOS 5 compiled in?

Upvotes: 7

Views: 3444

Answers (3)

Jirui
Jirui

Reputation: 189

The answer is Multi-thread. We can check by using sqlite3_threadsafe(), which returns 2.

0 - Single-thread
2 - Multi-thread
1 - Serialized

Q: @Ben Marten "unfortunately logging sqlite3_threadsafe() does not show any difference after the setting's been applied... "

A: sqlite3_threadsafe() only reports on the compile-time mutex setting of the [SQLITE_THREADSAFE] flag.

The return value of the sqlite3_threadsafe() interface is determined by the compile-time threading mode selection. If single-thread mode is selected at compile-time, then sqlite3_threadsafe() returns false. If either the multi-thread or serialized modes are selected, then sqlite3_threadsafe() returns true. The sqlite3_threadsafe() interface predates the multi-thread mode and start-time and run-time mode selection and so is unable to distinguish between multi-thread and serialized mode nor is it able to report start-time or run-time mode changes.

Upvotes: 0

Glen T
Glen T

Reputation: 1560

As per this answer - https://stackoverflow.com/a/7799021/40444

It appears you can do the following:

sqlite3_shutdown();
if (sqlite3_config(SQLITE_CONFIG_SERIALIZED) == SQLITE_OK) {
    NSLog(@"sqlite configured to be threadsafe);
}
sqlite3_initialize();

However it's unclear if this officially works.

Upvotes: 3

guruz
guruz

Reputation: 1614

OK, so sqlite3_threadsafe() returns 2 so it is compiled with SQLITE_CONFIG_MULTITHREAD on iOS. That is unfortunate, I would have liked Serialized.

sqlite3_config(SQLITE_CONFIG_SERIALIZED) unfortunately gives me SQLITE_MISUSE

Upvotes: 7

Related Questions