SQLite Forum

sqlite3_threadsafe() return value
Login

sqlite3_threadsafe() return value

(1) By anonymous on 2021-11-02 19:55:18 [link] [source]

Quoting https://sqlite.org/threadsafe.html:

"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 [...]"

This is not correct. sqlite3_threadsafe() is implemented as follows:

int sqlite3_threadsafe(void){ return SQLITE_THREADSAFE; }

(The sqlite3_threadsafe() C API docs seems fine, though.)

(2) By Larry Brasfield (larrybr) on 2021-11-02 20:12:15 in reply to 1 [link] [source]

I read the allegedly incorrect doc quote, saying "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 ...", as entirely consistent with the fact that it returns a constant set at compile time. The actual running mode, as set at runtime via pragma and possibly limited by compile-time preprocessor variables, can vary for a given instance of the library code, whereas the return from sqlite3_threadsafe() cannot.

I am inclined to say there is no doc bug here. However, the evidence suggests a better wording might be be clearer to you and perhaps others. Would you care to suggest something specific?

(3) By Keith Medcalf (kmedcalf) on 2021-11-02 20:35:06 in reply to 2 [link] [source]

How about simply stating fact:

sqlite3_threadsafe() returns the compile-time threadsafe setting as reflected by the SQLITE_THREADSAFE compile-time define. It does not return the current threadsafe operating mode for either the connection or the library, which may have been overriden at runtime (see ...).

(5) By anonymous on 2021-11-02 20:40:24 in reply to 3 [link] [source]

That would be an improvement.

(4) By anonymous on 2021-11-02 20:39:03 in reply to 2 [source]

I am inclined to say there is no doc bug here.

I think "unable to distinguish between multi-thread and serialized mode" is clearly wrong, but maybe I'm interpreting that totally wrong.

I suggest changing the first sentence of that paragraph to:

"The return value of the sqlite3_threadsafe() interface is determined by the compile-time threading mode selection, as set by the compile-time option SQLITE_THREADSAFE"

I suggest rewording the third sentence:

"If either the multi-thread or serialized modes are selected, then sqlite3_threadsafe() returns non-zero."

I suggest changing the last sentence to...:

"The sqlite3_threadsafe() interface is unable to report start-time or run-time mode changes."

That's my 2 cents :)

(6) By Larry Brasfield (larrybr) on 2021-11-02 21:23:50 in reply to 4 [link] [source]

This should be clearer. I chose less verbiage than you or Keith suggest because the immediate context would render it surplusage. Please feel welcome to voice reasoned disagreement with this opinion.

(7) By anonymous on 2021-11-02 21:29:30 in reply to 6 [link] [source]

Yes, that is a great improvement. Thank you so much, both of you.