When building transactionally protected applications, there are some special issues that must be considered. The most important one is that if any thread of control exits for any reason while holding Berkeley DB resources, recovery must be performed to do the following:
Recover the Berkeley DB resources.
Release any locks or mutexes that may have been held to avoid starvation as the remaining threads of control convoy behind the failed thread’s locks.
Clean up any partially completed operations that may have left a database in an inconsistent or corrupted state.
Complicating this problem is the fact that the Berkeley DB library itself cannot determine whether recovery is required; the application itself must make that decision. ...