标签 死锁 下的文章

在多线程中同时访问 SQLite 数据库,使用 sqlite3_stepsqlite3_prepare 和其他的函数可能引发 SQLITE_BUSYSQLITE_LOCKED 错误。SQLITE_BUSY 通常意味着 sqlite 需要一个锁,但是一定时间内无法获得。 SQLITE_BUSYSQLITE_LOCKED 最大的区别是:

  • SQLITE_LOCKED: if you get this from a sqlite3_step statement, you MUST call sqlite3_reset on the statement handle. You should only get this on the first call to sqlite3_step, so once reset is called you can actually "retry" your sqlite3_step call. On other operations, it's the same as SQLITE_BUSY
  • SQLITE_BUSY : There is no need to call sqlite3_reset, just retry your operation after waiting a bit for the lock to be released.

- 阅读剩余部分 -

在程序退出时,我们通常都会使用 WaitForSingleObject 等函数等待指定的信号或等待线程析构。最近在开发程序时突然遇到了在析构函数中使用 WaitForSingleObject 等待线程结束时造成程序阻塞的情况。经过仔细分析发现是在线程执行过程中更新了界面资源,而(UI线程)主线程此时被 WaitForSingleObject 阻塞(消息循环机制被阻塞),导致界面资源得不到更新,造成死锁。

- 阅读剩余部分 -