Possible bug fixes for issue #1025

Fix a possible race condition, and extended sanity checking when used with multiple atom spaces.