I'm guessing the most efficient way might be that when a thread enters the function it:
Either locks a mutex or atomically writes a variable to signal it's locked.
Checks whether it's been initialised, if not it initialises the value.
Either unlocks the mutex or atomically writes to the signal variable.
That would seem to me that each access is at minimum two atomic variable read/writes?
With a LazyCell, which works only for single thread uses and is used inside functions I guess one single atomic variable read/write can be used, something like if bHasBeenInitialised.
I mean the "Lock" part in the LazyLock name means that it's synchronised, so essentially it's the same as a Mutex. The fact that it's a fact just means that you don't have to have a second mutex/atomic to check initialisation, so a LazyLock is essentially like accessing a Mutex< > variable, right?
Also, I'm assuming the lazy_static and the other variations work the same?