Re: [sqlite] [EXTERNAL] Question about threadsafe
How did you start your processes? ie, is each process doing an sqlite3_open() or are you forking and passing the same pointer to multiple processes? What filesystem is the file located on? Is it a local filesystem or a network filesystem? Threadsafe is for protection against multiple entrance for threads WITHIN a single process. It does noting with respect to single threads in multiple processeses. --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-Original Message- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of Nick >Sent: Tuesday, 6 February, 2018 19:25 >To: sqlite-users@mailinglists.sqlite.org >Subject: Re: [sqlite] [EXTERNAL] Question about threadsafe > >Yep, Hick. We have the same understanding. >But all I found is that process B did not wait for the lock and began >to run >directly. > > > >-- >Sent from: http://sqlite.1065341.n5.nabble.com/ >___ >sqlite-users mailing list >sqlite-users@mailinglists.sqlite.org >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] [EXTERNAL] Question about threadsafe
Yes. But Process A begin Process A insert Process B begin Process B insert Process A end Process B end In fact, begin means "BEGIN" and end means "COMMIT". So I think the result is strange. And I guess the difference between Serilaized and Multithread is that if it is allowed to shared the structure sqlite3 *db (together with prepared statement) among threads. If I use Serilaized mode, then I could run sqlite3_open(db) for only one time and all the threads could use the unique "db". Is it right? -- Sent from: http://sqlite.1065341.n5.nabble.com/ ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] [EXTERNAL] Question about threadsafe
If you wrap your INSERTS into a single transaction, then one process wins and the loser waits until the winner is finished. If each INSERT is ist own (automatic) transaction, the processes will win/loose on each single INSERT, giving the appearance of two simultaneous writers, while actually they are always serializing. -Ursprüngliche Nachricht- Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im Auftrag von Nick Gesendet: Mittwoch, 07. Februar 2018 03:25 An: sqlite-users@mailinglists.sqlite.org Betreff: Re: [sqlite] [EXTERNAL] Question about threadsafe Yep, Hick. We have the same understanding. But all I found is that process B did not wait for the lock and began to run directly. -- Sent from: http://sqlite.1065341.n5.nabble.com/ ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ 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 sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] [EXTERNAL] Question about threadsafe
Yep, Hick. We have the same understanding. But all I found is that process B did not wait for the lock and began to run directly. -- Sent from: http://sqlite.1065341.n5.nabble.com/ ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] [EXTERNAL] Question about threadsafe
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 [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im Auftrag von Nick Gesendet: Dienstag, 06. Februar 2018 12:52 An: sqlite-users@mailinglists.sqlite.org Betreff: [EXTERNAL] [sqlite] Question about threadsafe I use sqlite 3.16.2 in Android system and I have configured journal_mode=WAL, threadsafe=1. 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 supported. 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 1 records(in Transaction) into the db simultaneously. 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 2 at last. So I think multiple write threads is not allowed even though I use threadsafe=1 in wal mode? -- Sent from: http://sqlite.1065341.n5.nabble.com/ ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ 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 sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users