Split the queue into atomic and nonatomic versions

Also fix the race condition involved with a reader not getting the message when
a queue is closed.