Thank you Simon/Igor.

I got the answer.

>>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.

How can I achieve this with single thread?

My Req. is: I have to write a wrapper for sqlite3. This wrapper will be
called by different clients from different threads within the process.
Requests might be read or write. Wrapper will have static sqlite3*. So all
clients shares the same sqlite3*. To simulate this, I created this sample
application.

doubt: How can I achieve this single thread when multiple clients are
called.

Am I right?

Regards,

On Mon, Jul 23, 2012 at 8:19 PM, Igor Tandetnik <itandet...@mvps.org> wrote:

> 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<http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users>
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to