added atomic and non-atomic versions for demonstration