Deadlock in database.cpp