Skip to content

Comments

Replace SQLiteWriter mutex with SQLite mutex#11

Open
wandernauta wants to merge 1 commit intoberthubert:mainfrom
wandernauta:combine-mutex
Open

Replace SQLiteWriter mutex with SQLite mutex#11
wandernauta wants to merge 1 commit intoberthubert:mainfrom
wandernauta:combine-mutex

Conversation

@wandernauta
Copy link

@wandernauta wandernauta commented Dec 22, 2024

The SQLiteWriter commit thread and the user's main thread share the same connection to the underlying database. The threads are synchronized with a std::mutex on SQLiteWriter.

However, the SQLite connection already carries its own (recursive) mutex which we can use instead. This simplifies the design slightly: there can no longer be a situation where a thread grabs the SQLiteWriter-side lock but has to wait for the SQLite-side lock, which would be very confusing.

This will not work in builds of SQLite with non-default threading modes, but in such cases sharing a connection among threads is unsafe anyway.

The SQLiteWriter commit thread and the user's main thread share the same
connection to the underlying database. The threads are synchronized with
a std::mutex on SQLiteWriter.

However, the SQLite connection already carries its own (recursive) mutex
which we can use instead. This simplifies the design slightly: there can
no longer be a situation where a thread grabs the SQLiteWriter-side lock
but has to wait for the SQLite-side lock, which would be very confusing.

This will not work in builds of SQLite with non-defualt threading modes,
but in such cases sharing a connection among threads is unsafe anyway.
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.

1 participant