I think the way you did it is better, due to the race condition I described.