Hi everyone,

I am using sqlite 3.3 awhile now for some statistic updates in multithreaded enviroment. Now I would like to move on to 3.5.2 use it more for other tasks too. Since the sqlite db is placed here on a fs, which has a broken fcntl, I disabled it by putting "#define fcntl (A,B,C) 0". As I only use it within the same process with couple of threads, I am doing currently the locking with pthread mutexes like:

each thread  {

              /* worker stuff */
             ...
             if new stats did arrive:
            compete on mutex
              -> when lock is acquired, do
                   open database
                   read something (eg sqlite_exec "select ....")
if does not exist, do write (sqlite_exec "insert into table...") close database -> release lock
                }

Of course, this is very simple and serializing everything including open/close of the db image. My question is now, what could I improve with 3.5.x now as it has buildin thread safety for the same database (as mentioned in 34to35) but I did not find how this thread safety is made (using mutexes, rwlock? still fcntl?) I cannot rely on fcntl, so for thread-safety, it's all up to pthread mutexes/rwlock

Following idea's crossed my mind:

a)
only open the database once in each thread and keep the connection open, but lock write operations with mutex (rwlock). This would give all threads concurrency for reading and only serialize writing. For this scenario, I am unsure about the fact if one thread did a write, how all other threads will notice the change in the database. Is this now handled internally by sqlite 3.5? Can I keep open multiply connection to the same database and operate on it. Maybe the VFS will take in effect now. So thats why I am asking to be sure.

b)
Instead each thread has it's own connection handle create one global and share it along with all threads (and protect it by mutex?). This would be an improvement if a) is not possible. At leased the database would not be opened/closed all the time but serialized read/write commands.

Most of the time, only "select" is happening on the same table. So concurrent access to the table would be perfect. To use the new vfs or thread-safety over the same database, do I need to initialize anything?

Thanks in advance,

Xat


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

Reply via email to