[repost after initial e-mail was mangled up with HTML/XML tags]
hi,
Just to let you know. I did some more tests and skimmed through the source
code. Here a quick description of how the reloading from disk works in a
multithreaded process:
(1)
If shared cache is disabled, each call to sqlite3_open() will result in a db
handle with its own btree and page cache. If the page cache is not shared, each
db handle needs to refresh its page cache from disk if some other thread or
process using some other db handle has written to the database. The magic piece
of code is in pager.c: pagerSharedLock().
if( memcmp(pPager->dbFileVers, dbFileVers, sizeof(dbFileVers))!=0 ){
pager_reset(pPager);
}
If the version number read from the file on disk is different than the version
number in memory, reset the pager cache.
(2)
If shared cache is enabled, and it's a disk-based database (not in-memory, not
temporary) each call to sqlite3_open() results in a db handle that points to
the same shared btree and page cache (the relevant code can be seen in the
implementation of sqlite3BtreeOpen() ). This also means if there's a write
transaction from any of the db handles, the page cache version number is
increased. This eventually leads to the fact the version number on disk and
version number in the page cache are the same. I.e. no reload happens.
Hope that helps bit.
Markus
PS: Below some sample code I used. Simply compile and run with "sampleapp
db-file". Note that it deletes the file first if it exists. Run the
application with e.g. "strace -f" (Linux distro) to see system calls. The
application creates two db handles to the same db (one in the main thread and
one in a newly started thread). The first one only writes and the second one
only reads.
#include
#include
#include
#include
#include
/*
* Sample code. No guarantees for correctness
*/
/*
* some global variables that are quick'n'dirty but do the job
*/
char** argv_global;
/*
* A callback function needed for sqlite3_exec. Copied from sample code.
*/
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces.
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users