Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why sqlite_orm doesn't use sqlite3_open_v2() to let it be thread-safe? #1348

Open
yangsongx opened this issue Sep 18, 2024 · 2 comments
Open
Labels

Comments

@yangsongx
Copy link

yangsongx commented Sep 18, 2024

I know the sqlite3_open_v2() can support the therad-safe. But it didn't be called by sqlite_orm.h

Can I just replace the sqlite3_open()/sqlite3_close() with sqlite3_open_v2()/sqlite3_close_v2() to let sqlite_orm.h be thread-safe?

Or , is the default sqlite_orm.h already be thread-safe?

(PS, I knew the sqlite3 needs to enable the ./configure --enable-threadsafe to let it support thread safe in Sqlite3 itself)

@fnc12
Copy link
Owner

fnc12 commented Oct 9, 2024

where did you find that sqlite3_open_v2 make the connection thread-safe?

@fnc12 fnc12 added the question label Oct 9, 2024
@yangsongx
Copy link
Author

Hi, Thanks for you reply.

https://www.sqlite.org/c3ref/open.html

The sqlite3_open_v2() interface works like sqlite3_open() except that it accepts two additional parameters for additional control over the new database connection. The flags parameter to sqlite3_open_v2() must include, at a minimum, one of the following three flag combinations:

There is a flag in the sqlite3_open_v2():
[SQLITE_OPEN_FULLMUTEX]

The new database connection will use the "serialized" threading mode. This means the multiple threads can safely attempt to use the same database connection at the same time. (Mutexes will block any actual concurrency, but in this mode there is no harm in trying.)

And it also provide sqlite3_busy_handler() API to let caller to keep waiting when writing to DB with multiple threads.

related description:

  - https://www.sqlite.org/c3ref/busy_handler.html
 - https://www.oreilly.com/library/view/using-sqlite/9781449394592/re238.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants