More than one concurrent writer is not supported. WAL mode only allows readers 
to see the state of the db as it was at the start of their transaction while 
writers' changes are written to the WAL file.

Threadsafe refers to the interoperation of multiple threads within a single 
process. Single thread means that only one thread of a process can use SQLite 
at any time. Multithread means that several threads within a single proces may 
cal SQLite, but only one thread at a time is allowed per connection. Serilaized 
means that any thread can call SQLite for any connection at any time, but the 
second caller will block until the first one returns from the library.

What you tested is multiple processes accessing the same db file. This uses the 
normal locking protocol. The first process to establish a write lock will 
proceed with its work until the transaction ends (commit or rollback), 
releasing the lock that the second process was waiting for. Only then will the 
second process be able to continue.

-----Urspr√ľngliche Nachricht-----
Von: sqlite-users [] Im 
Auftrag von Nick
Gesendet: Dienstag, 06. Februar 2018 12:52
Betreff: [EXTERNAL] [sqlite] Question about threadsafe

I use sqlite 3.16.2 in Android system and I have configured journal_mode=WAL, 

My understanding is that:
        WAL => readers and only one writer can run at the same time.
        threadsafe=1 => mutex is used in serialized mode so that two writers is 
Is it correct?

But I ran a simple test:
Two processes will run sqlite3_open() respectively to open the same db. Then 
both of the two processes will insert 10000 records(in Transaction) into the db 
But I find that:

Process A begin
Process A insert
            Process B begin
            Process B insert
Process A end
            Process B end

Which I guess the Process B did not sleep at all?
And the count of records is less than 20000 at last.

So I think multiple write threads is not allowed even though I use
threadsafe=1 in wal mode?

Sent from:
sqlite-users mailing list

 Gunter Hick | Software Engineer | Scientific Games International GmbH | 
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 
1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
sqlite-users mailing list

Reply via email to