Guard against potential race condition by atomically check-and-allocate