SQLite Forum

sqlite3_threadsafe() return value
Login

sqlite3_threadsafe() return value

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

Quoting [https://sqlite.org/threadsafe.html](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](https://sqlite.org/c3ref/threadsafe.html) docs seems fine, though.)

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

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]

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]

That would be an improvement.

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

> 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]

<u>[This should be clearer](https://www.sqlite.org/docsrc/info/fafb4edaa391548a)</u>. 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]

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