Saturday, February 19, 2011

Is SQLite thread safe under this situation?

I require database access operations from several threads, through a singleton object, which holds a database connection. I read from SQLite3's website, saying that 'an sqlite3 structure could only be used in the same thread that called sqlite3_open() to create it. You could not open a database in one thread then pass the handle off to another thread for it to use'. I'm wondering under my situation, is there any threat of thread-unsafety?

From stackoverflow
  • If the SQLite library is compiled with -DSQLITE_THREADSAFE you are OK with the more recent SQLite 3 versions.

    The author of SQLite says:

    Beginning with version 3.5.0, SQLite enforces this itself using its
    own internal mutexes, so the application is free to (try to) use the
    same database connection from multiple threads at the same time.

0 comments:

Post a Comment