Some utility functions.

That has the race condition I deliberately wrote the code to avoid...