Hello everybody,

I know there are lots of documentation about sqlite and multithreading
and yes, I have read all of it! ;) I'm to the point where I think
about restructuring my application in order to make it more reactive,
and I'd like to ask for your wise comments.

The scheme I would like to implement is as follow:

- The main thread (which displays the GUI and must therefore not be
frozen by some long query) is the only thread that does write accesses
to the database. Writing remains very seldom and fast, though.
- Around this thread, several other threads may exist that run
read-only queries on demand by the main thread (typically, when the
user wants to display something in the user interface. I need to use a
different thread because I don't want to block the GUI while the
request is running). When the request is finished, the result is
displayed by the main thread. However, the main thread may also want
to abort that request, for instance if the user decides to display
something else by the meantime. The problem is that there may be
several of these peripheral threads (I estimate up to 5), and they
must all be interruptible individually.

This is where my problem lies: sqlite has a function to interrupt
queries (sqlite3_interrupt), but it stops all the queries of a given
connection. Therefore, to ensure all queries are individually
interruptible, I must open one sqlite connection per thread. By doing
so, and considering that the main thread only writes seldomly, I think
I would not experience any GUI is freeze, as all the lengthly queries
would be executed by other threads that can be interrupted if the user
decides to take some further action before they complete.

The only freeze condition that I may have would be when the main
thread wants to write to the database while other threads are still
reading it. In that case, the GUI may freeze while the main thread
tries to acquire its lock. However, I think I can easily workaround
that using another thread that is only dedicated to writing and
buffers write requests as they arrive.

This design will require a major overhaul of my application, so I'd
like to make sure it is a good idea. I'd like to avoid using multiple
connections, but I feel like I have no choice there. Would anyone have
something to say against that design or would suggest a better idea?

Thanks,
Alex.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to