Interprocess SQLite Thread Safety (on iOS)

后端 未结 2 928
别跟我提以往
别跟我提以往 2021-01-12 02:37

I\'m trying to determine if my sqlite access to a database is thread-safe on iOS. I\'m writing a non App Store app (or possibly a launch daemon), so Apple\'s approval isn\'

2条回答
  •  自闭症患者
    2021-01-12 03:13

    I don't think any of this is news to you, but a few thoughts:

    In terms of enabling multi-threading (either serialized or multi-threaded), the general counsel is that one can invoke sqlite3_config() (but you may have to do a shutdown first as suggested in the docs or as discussed on SO here) to enable the sort of multi-threading you want. That may be of diminished usefulness here, though, where you have no control over what sort of access iOS is requesting of sqlite and/or this database.

    Thus, I would have thought that, from an academic perspective, it would not be safe to read this system database (because as you say, you have no assurance of what the OS is doing). But I wouldn't be surprised if iOS is opening the database using whatever the default mode is, so from a more pragmatic perspective, you might be fine.

    Clearly, for most users concerned about multi-threaded access within a single app, the best counsel would be to bypass the sqlite3_config() silliness and just simply ensure coordinated access through your own GCD serial queue (i.e., have a dedicated queue through which all database interactions go through, gracefully eliminating the multi-thread issue altogether). Sadly, that's not an option here because you're trying to coordinate database interaction with iOS itself.

提交回复
热议问题