Previous Blog "SQLite: Multi-threaded Operation database" is locked "solution" by registering the delay function to deal with the problem of database lock. This approach solves the problem, but the delay slows the progress when multiple threads write large amounts of data to the database.
Think of method Two:
1. Create a linked list, link the structure of the following format, thread 1, thread 2, thread 3 ... Instead of rewriting the database directly, insert the SQL statement into the linked list;
struct*buf;uint32_t len;} sqlitem_t;
2. create a separate thread, full-time read SQL statements from the linked list, and rewrite the database.
So that only one thread to operate the database, the database is locked the problem can be avoided, the database processing efficiency is greatly improved.
3. use transactions to further improve SQLite processing performance
Ideas are as follows:
Execution "begin TRANSACTION; " statement to execute multiple insert/update/delete/... Statement execution "commit transaction; " statement
SQLite: Multi-threaded Operation database "database is locked" Workaround (ii)