Sqlite: multi-threaded database operation "database is locked" solution (2), sqlitelocked
In the previous blog "sqlite: multi-threaded database operation" database is locked "solution", we registered a latency function to solve the database lock problem. This method can solve the problem, but when multiple threads write a large amount of data to the database, the delay will slow down.
Method 2:
1.Create a linked list and link the struct in the following format: thread 1, thread 2, thread 3... instead of directly rewriting the database, insert SQL statements into the linked list;
Typedef struct {uint8_t * buf; uint32_t len;} sqlItem_t;
2.Create an independent thread to read SQL statements from the linked list and rewrite the database.
In this way, only one thread can operate on the database, and the database can be prevented from being locked, which greatly improves the processing efficiency of the database.
3.Use transactions to further improve sqlite processing performance
The idea is as follows:
Execute the "begin transaction;" statement to execute multiple insert/update/delete/... statements to execute the "commit transaction;" Statement
How does SQLite solve database is locked?
Sqlite is a file. A process can be opened and written, but other processes cannot be written. Arrange your multi-process properly.
Hello, database is locked when I insert data to the sqlite database through the input content in the interface when I am working on a project! Ask you
The database process is not closed and released in time after it is opened ......