Using atomicModifyIORef'.