Avoiding a race condition