uses the double-checked locking to speed up subsequent calls to the same
function.