Alexey Romanov
Alexey Romanov

Reputation: 170815

How to check SQLite connection's threading mode?

Is it possible to check the threading mode of an active SQLite connection? I know about sqlite3_threadsafe(), but

The return value of the sqlite3_threadsafe() function shows only the compile-time setting of thread safety, not any run-time changes to that setting made by sqlite3_config().

Upvotes: 6

Views: 3156

Answers (2)

Barry Smith
Barry Smith

Reputation: 128

Hmmm, seven year old question. You have answered it yourself, though. For the next person who comes looking:

sqlite3_db_mutex will return NULL if threading mode is Single-thread or Multi-thread.

So we have:

(sqlite3_threadsafe , sqlite3_db_mutex) : threading mode

(0 , NULL) : Single-thread

(1 , NULL) : Mutli-thread

(1 , valid) : Serialized

Upvotes: 2

Alexey Romanov
Alexey Romanov

Reputation: 170815

Here is a partial answer:

sqlite3_mutex *sqlite3_db_mutex(sqlite3*);

This interface returns a pointer the sqlite3_mutex object that serializes access to the database connection given in the argument when the threading mode is Serialized. If the threading mode is Single-thread or Multi-thread then this routine returns a NULL pointer.

Now I only need a way to distinguish Single-thread from Multi-thread...

Upvotes: 1

Related Questions