SQLite Forum

Multithread processing, storing in memory and writing to database
Login
Advantages of Approach#1 is that writes are independent and concurrent.  
But you'll block the threads, to copy the data over eventually.

Approach#2 is bad, since the one DB must serialize everything,  
which makes all threads wait on a global mutex basically, when they need to write anything.

A third approach is to use a concurrent queue, enqueue from the threads,  
dequeue from the main thread to write into the DB. If you are in C++,  
I'd recommend `https://github.com/cameron314/concurrentqueue` which is  
lock-free and performant. There are others from Boost, Facebook Folly, etc...

The approach#3 is similar to #2, but with the crucial difference that you are  
trading more memory use (to store in the queue) for better concurrency.  
And since you guarantee serialized use of SQLite, you can build it w/o mutex  
support too, gaining a little more speed.

My $0.02. --DD