SQLite3 and multiple processes

前端 未结 4 1920
广开言路
广开言路 2020-12-08 15:18

How should one ensure correctness when multiple processes access one single SQLite database file?

4条回答
  •  春和景丽
    2020-12-08 15:56

    Any SQLite primitive will return SQLITE_BUSY if it tries to access a database other process is accessing at the same time. You could check for that error code and just repeat the action.

    Alternatively you could use OS synchronization - mutex on MS Windows or something similar on other OSes. The process will try to acquire the mutex and if someone else already holds it the process will be blocked until the other process finishes the operation and releases the mutex. Care should be taken to prevent cases when the process acquires the mutext and then never releases it.

提交回复
热议问题