Rafi Cohen wrote:
Hi, I read the good article on this subject and also the api refference
in the documentation and still feel that I need to ask the following
question.
My application has 2 threads. The main one needs to retrieve data thru
select commands but does not change the database, while the other thread
will change the database quite often.
My questions are: should I open the database in each thread separately
or can I open it once for the whole program? in the second case, does it
matter inh which thread I open it? last, if the main thread happens to
retrieve data while the other thread is in a transaction changing the
database, I would prefer the main thread wait till the end of the
transaction and retrieve the most updated data. How do you suggest to
implement it?
looping on sqlite3_busy_handler should be the way to go?
Thanks, Rafi.

Rafi,

For your access you would be best off to have the main thread open the connection and pass a reference to it to the other thread (or you could use a global connection variable). Then use a mutex to have the threads block until they can get exclusive access to the connection. Once they have the mutex they can do their read or write with no concern for interruption from the other thread (it will block on the mutex if it tries to start a database access).

HTH
Dennis Cote

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to