initOnce
fn
auto ref initOnce(alias var)(lazy typeof(var) init)Initializes var with the lazy init value in a thread-safe manner.
The implementation guarantees that all threads simultaneously calling initOnce with the same var argument block until var is fully initialized. All side-effects of init are globally visible afterwards.
Parameters
var | The variable to initialize |
init | The lazy initializer value |
Returns
A reference to the initialized variable
fn
auto ref initOnce(alias var)(lazy typeof(var) init, shared Mutex mutex)Same as above, but takes a separate mutex instead of sharing one among all initOnce instances.
This should be used to avoid dead-locks when the init expression waits for the result of another thread that might also call initOnce. Use with care.
Parameters
var | The variable to initialize |
init | The lazy initializer value |
mutex | A mutex to prevent race conditions |
Returns
A reference to the initialized variable
fn
auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex)ditto