Avoid race conditions during registration using lock.