On 7/23/2012 10:30 AM, Durga D wrote:
Unless your threads do something else in parallel, you could just as well
do all SQLite work on a single thread

doubt: all are parallel threads. started at same time. one thread is
writing and others are reading at the same time by using same sqlite3*.

Not really. What really happens is, one of the threads does some work, while the other three are sitting waiting on a mutex.

In this scenario, all are parallel.

Again - every SQLite API call acquires a mutex associated with the connection. If that mutex is already taken, then the thread sits there waiting for it to be released. In other words, two SQLite calls on the same connection never execute at the same time - they are serialized on the mutex. Threads effectively take turns to make these calls.

my main doubt is: same sqlite3* is passing to 4 threads from the primary
thread.

Is it correct way to implement multiple readers and single writer?

There are no technical problems with this, if that's what you are asking. It would work. But since all the work is serialized, a single thread that does all the reading and writing would be just as fast, if not slightly faster. You are adding complexity but are not gaining any performance out of it.
--
Igor Tandetnik

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

Reply via email to