两个函数同时访问数据库

时间:2015-05-29 13:55:25

标签: android c++ sql

我有功能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;
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您使用这些函数之间共享的一个帮助程序实例,则所有数据库访问代码都是串行的。

请检查:http://touchlabblog.tumblr.com/post/24474750219/single-sqlite-connection

相关问题