// Double checked locking to avoid expensive locks when not required.
// 1) First we atomically check if the instance is valid; in this case it can safely be returned directly without locking.
// 2) If the instance is actually null, then we can no longer perform the operation atomically, so need to lock the mutex. This will happen only once in the program's lifetime. One the mutex is locked, check if the instance is still null
// (as another thread might have changed it by this point). If it's still null, allocate and update the atomic instance pointer, unlock mutex and return the reference.