[Interest] QSqlDatabase and threads
Mark Brand
mabrand at mabrand.nl
Thu May 30 20:04:03 CEST 2013
> On Thursday 30 May 2013 18:03:15 Witold E Wolski wrote:
>
>
> I am using threading to speed up compuation. Each thread produces some
> results which I would like to store in a sqlite file.
>
>
>
> My idea is to have something like an monitor object which has an
> QSqlDatabase member and a insert method which is synchronized using a mutex.
>
>
>
> The problem I am actually running into is that the QSqlDatabase member gets
> ??? once the pointer to the Monitor object is passed into to the threads.
>
It is not safe to access a QSqlDatabase from more than one thread, except for
clone(). However, sqlite itself is thread-safe. There's nothing wrong with a
separate QSqlDatabase object in each thread opening its own connection to the
same sqlite database. Let sqlite solve your concurrency problem. Sqlite is in
a better position to manage concurrent database access than your application
could ever hope to be, since it can do it at the level of individual database
objects.
Mark
More information about the Interest
mailing list