core: ensure single threaded access to database