Fix DB corruption potential

Make sure that the dbm object is closed before another thread might come along.  Out of an overabundance of caution,
also join() existing cfgwriter thread to make sure that only one thread touches it at a time.  In theory, it should only possibly
be after the db is closed, but take no chances.