Question regarding thread safety
Hi,
Thank you for this library.
I just wanted to ask if there are any guarantees regarding thread safety. More specifically, if I compile sqlite3 with thread safety enabled can I use the same sqlpp::sqlite3::connection object for requests from multiple threads? I suspect that the answer is no, but want to make sure anyway.
Hi,
I am not really an expert for sqlite3. The sqlpp::sqlite::connection wraps an sqlite3 connection. You will get the same thread guarantees. I assume that means that you should not share a connection between threads, but I am not sure.
Best,
Roland
@rbock thanks for quick reply.
SQLite has a so-called serialized mode that allows using "SQLite by multiple threads with no restriction". At a glance I found a couple of things in sqlpp (like this one) that could probably cause race conditions.
Sharing db connections between threads might not be a great idea, but I was just wondering if it's possible with this library (edit: I mean without explicit locks).
Good point about the transaction state. I'll would need to think about that for a bit (which will take a while because of other constraints). My tendency would be to say you are right: Sharing is dangerous without explicit locks.
Thank you for answering my questions.
I'll would need to think about that for a bit (which will take a while because of other constraints)
Should I close the issue then or leave it as reminder? I'll leave it so you can close it yourself if you want to.
Hi, what about MySQL/MariaDB ? I have Server in Qt which is highly multi-threaded. Each thread in requires its own connection to database. is this same in sqlpp11 ?
@SmitTheTux That would be the safe option, yes.
Finally added a few word of documentation:
https://github.com/rbock/sqlpp11/blob/main/docs/Threads.md