两个函数同时访问数据库
two functions accessing database at the same time
我有函数A和函数B。
函数A在循环中运行。每6秒更新一次数据库。
函数B在用户更改内容时更新数据库。
在长时间运行期间,这两个函数试图同时访问数据库,导致sqlite崩溃。
请建议一个避免这种情况的方法。
下面是函数B
while(1)
{
tvAudioMgrInstance->updateDatabase();
if(errno != EINTR)
{
// In Android sleep() function takes argument as seconds
rc = sleep(PERIODIC_UPDATE_DATABASE_TIME);
}
if((rc != 0)||(errno == EINTR))//even checking errno alone is enough..as errno is global to the thread alone
{
tvAudioMgrInstance->updateDatabase();
#if TVAUDIOMANAGER_LOG_ENABLE
ALOGD("Exit AUDMGR Pthread");
#endif
break;
}
}
如果在这些函数之间共享一个helper实例,则所有数据库访问代码都是串行的。
检查:http://touchlabblog.tumblr.com/post/24474750219/single-sqlite-connection
相关文章:
- 使用 Qt5 SQL 进行异步数据库访问的策略
- 根据用户名和密码 Qt C++重新访问数据库值
- 缓存和访问数据库数据的有效方法?
- 可以删除SQLite3数据库文件,并且仍然可以访问
- 没有绝对路径无法访问数据库
- 使用连接器 c++ 访问 MYSQL 数据库(如何将路径添加到我的标准搜索目录)
- 访问数据库-QODBC驱动程序在管理员上执行授予
- 如何从Qt使用密码访问Sqlite数据库
- 如何为数据库设置密码,以便没有人可以访问它
- 如何使用QT/C 中的多线程用API访问我的数据库
- 数据库访问对象设计模式
- SQLite C++多个进程以只读模式访问数据库时"数据库已锁定"
- 仅使用一个用户id和密码访问数据库
- Okcupid.com(无需访问数据库即可查找匹配项!?)
- C++/MySQL - 通过主机地址访问数据库时'Unknown MySQL server host';没有 IP
- 使用线程访问数据库
- 在并行线程中访问数据库,可行的选项
- 无需安装即可访问C++数据库
- Quora和Facebook使用哪些C++库来访问数据库
- 两个函数同时访问数据库