sqlite3.dylib: illegal multi-threaded access to database connection

后端 未结 4 1639
[愿得一人]
[愿得一人] 2021-01-02 08:40

I have an iOS app that uses sqlite3 and I\'m facing issues with multi-threading crashing the app with the illegal multi-threaded access to database connec

4条回答
  •  盖世英雄少女心
    2021-01-02 09:32

    From https://www.sqlite.org/threadsafe.html

    SQLite supports three different threading modes:

    Single-thread. In this mode, all mutexes are disabled and SQLite is unsafe to use in more than a single thread at once.

    Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.

    Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.

    In iOS,SQLite default threading mode was SQLITE_OPEN_NOMUTEX(equal to Multi-thread),which was not safe when multiple threads write or read the database simultaneously use one connection. Change threading mode to serialized may helpful for you.You can change threading mode use sqlite3_config() or sqlite3_open_v2().

提交回复
热议问题