On Mon, 07 Jan 2013 05:43:50 -0800
Roger Binns <rog...@rogerbinns.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 07/01/13 00:22, Eduardo Morras wrote:
> > opened before the fork, and after it the childs use the database
> connection. I don't want to corrupt the database,
> 
> https://sqlite.org/faq.html#q6
> 
> You can't use the database across forks.  Parent and child would both
> consider themselves owners of open databases and silently corrupt each
> other's work and interfere with each other's locks.  You will corrupt the
> database. You need to close all databases and then do the fork, and then
> open databases in the children.

Years using sqlite (since 3.0 days) and never seen that advice about fork. It's 
the first time i use it with fork. Nothing wrong happened yet because i tested 
the app wrongly, perhaps it worked for now because -DSQLITE_THREADSAFE=1 
(serialized) was setted and may bang my foot in future. I'll change it, so 
childs and parent will open the connection after the fork. 

> In APSW I provide a fork checker.  This is done by providing an
> alternative mutex implementation that records the process id a mutex was
> created in and then checking the mutex is only ever used in the same
> process id.  (Each database connection has its own mutex.)
> 
> The code that does this:
> 
>   https://code.google.com/p/apsw/source/browse/src/apsw.c#704
> 
> In my benchmark tests I measured a slowdown of 1%.  ie if your code did
> nothing but SQLite calls then you can expect it to be about 1% slower.
> 
> I strongly recommend you do something like this to ensure that no
> developer accidentally has databases used across forks.

Interesting way to bypass the fork() problem and enhace sqlite. It may work 
with other types of applications architectures, not only fork(), f.ex. using 
exec*() after fork so you get 3 different apps using the same db, but i prefer 
to fix the bug.

> Roger

---   ---
Eduardo Morras <emorr...@yahoo.es>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to