On Thu, Oct 31, 2013 at 9:56 AM, Sandu Buraga <sandu.bur...@gmail.com>wrote:

> Hi,
>
> I am using SQLite 3.7.9, and QNX 6.5.0 running on Intel x86 machine. I am
> having a use-case with multiple readers threads and one writer thread, all
> running in the same process. No other process is using the SQLite database
> file.
>
> I tried to enable WAL feature, but with no success so far. Each thread has
> it's own handle:
>
> res = sqlite3_open_v2( m_FilePath.getBuffer(), &dbHandle,
>
> SQLITE_OPEN_READWRITE|SQLITE_OPEN_WAL|SQLITE_OPEN_FULLMUTEX|SQLITE_OPEN_PRIVATECACHE,
> NULL );
>
> immediately after I am making these PRAGMA statements for the new opened
> handle
>
> "PRAGMA main.journal_mode=WAL;"
> "PRAGMA temp_store=MEMORY;"
>
> So if I have 5 threads, I am calling the above sequence 5 times for each
> distinct handle
>

(1) WAL mode is a persistent property of the database file.  Set it once
from a single-threaded connection and it will stay set forever.  You should
not try to set WAL mode on each connection separately.

(2) WAL mode uses mmap() to get access to a small piece of memory that is
shared between all connections.  But the mmap() is unreliable on many
version so QNX.  If you must use WAL mode, first run "PRAGMA
locking_mode=EXCLUSIVE".  That will prevent all processes but the first
from connecting to the database (though many threads from within that one
process can have their own individual connections).  And since only a
single process is accessing the database, heap memory instead of mmap()
memory is used for the shared memory region.  This trick enables WAL mode
to work reliably on QNX.



>
> When the code is executed I am getting frequently "databed locked"
> messages. I tried to diagnose the issue, by enabling also the WAL traces in
> the SQLite amalgamation, but I noticed no message, so for me it looks like
> the WAL feature was not enabled. By analyzing the existed traces it looks
> like thread 2 - reader is getting a SHARED lock, while later process 3 -
> writer is trying to get an EXCLUSIVE lock.
>
> Any suggestion would be appreciated.
>
> Regards,
> Sandu
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



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

Reply via email to