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

Threadsafe connection #1395

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft

Conversation

trueqbit
Copy link
Collaborator

@trueqbit trueqbit commented Feb 4, 2025

With C++20 a more light-weight binary semaphore can be conditionally used to synchronize opening and closing a database connection.

Therefore, the connection holder should be minimally invasive and performant in all variants:

  1. single-threaded use
  2. opened once (open forever)
  3. concurrent open/close

Note: One important change is that things involved around setting up a database connection - like creating application-defined functions, setting pragma or limit values - must be done under the same synchronization point right after opening the database.
Caveat: Currently the connection cannot yet be recursively retained; think: user-provided 'on open' handlers.

The connection holder should be performant in all variants:
1. single-threaded use
2. opened once (open forever)
3. concurrent open/close

Hence, a light-weight binary semaphore is used to synchronize opening and closing a database connection.
A user-provided 'on open' handler and connection control options can now be specified in a declarative way when making the 'storage' object.
@trueqbit trueqbit force-pushed the experimental/threadsafe_connection branch from 564025d to 14a2aa0 Compare February 10, 2025 19:03
@trueqbit trueqbit force-pushed the experimental/threadsafe_connection branch from f82faa4 to 3ed7507 Compare February 16, 2025 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants