sqlite in-memory db and multithreading

久未见 提交于 2019-12-04 13:04:44
Doug Currie

If you open the connection to your in-memory database using serialized mode, then the connection may be shared among multiple threads.

For this to work, your SQLite must be compiled threadsafe -- this is the default.

Depending on your application, you may get better performance with a large shared cache to an on-disk database, or with WAL mode if you have many reader threads.

Example:

sqlite3 *pDb

if (sqlite3_open_v2(":memory:", &pDb, SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {

    start_thread1_with_db_handle(pDb);

    start_thread2_with_db_handle(pDb);

    // etc.
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!