Thank you Igor for the prompt reply.
 
Apologies, I am a beginner and hence some more naïve questions:
 
I am starting simple where I have exe1 having 1 connection and exe2 having 
another connection.
Now if both of them open the connections in mutex mode, will the read/write 
requests be serialized. It seems you are saying No.
 
If so, then what is the advantage of mutex? Like, I would expect that  a single 
thread connection will anyways serialize its requests from the client. What am 
I missing?
 
Finally, how do I enable WAL mode and this different locking mechanisms? 
Specifically, can I do that in System.Data.SqLite client? 
 
Also, what happens when 2 connections(with mutex) try to write? Will one of 
them get sqlite_busy?
 
 
Thanks,
Kushal.
 

________________________________
 From: Igor Tandetnik <itandet...@mvps.org>
To: sqlite-users@sqlite.org 
Sent: Friday, May 4, 2012 11:04 AM
Subject: Re: [sqlite] Locking/Concurrency
  
On 5/4/2012 1:52 PM, KUSHAL SHAH wrote:
> I am trying to use SQLite in my .NET project. Client APIs are from 
> System.Data.SqLite. Can you please help with below:
> 
> It seemsthat multiple
> threads can actually read simultaneously from a sqlite Db. However, I am
> confused about the write part. Will SQLite manage the write requests or the
> user has to have specific flags/locks on the connection?

Every connection has an associated mutex, and every SQLite API function calls 
are synchronized on this mutex.

> I couldn’t find good documentation around it.

http://sqlite.org/threadsafe.html

> Specifically, I am looking for the
> following scenarios:
> 
> 1.       I am reading Db and on another thread is
> writing to that Db. Do I need specific flags on each of the connections? If 
> so,
> which ones?

Ah, so it's two separate connections? Earlier, you were talking about "the" 
connection. With multiple connections, different rules apply:

http://sqlite.org/lockingv3.html
http://sqlite.org/wal.html

Unless you enable WAL mode, you won't be able to read on one connection and 
write on another simultaneously.

> 2.       Both threads want to write to the Db? What
> flags/locks can I have in my code to achieve that, if at all?

You can't have two writing connections, even in WAL mode. The two threads may 
share the same connection, but then they would be effectively serialized 
anyway, so you won't get any benefit from having two of them.
-- Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
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