Stdlibsync
once
import std::sync::once; · source
Once
type struct Once {
inner: OnceInner*;
static new() -> Once;
call_once(&this, init: () -> void) -> void;
}
Run an initializer exactly once across all threads. The first caller runs it; every other caller blocks until it finishes, and thereafter call_once returns immediately.
import std::sync::once;
mut init: Once = Once::new();
init.call_once(() -> void { setup_tables(); });
The initializer is a () -> void function pointer, and a non-capturing lambda is one.
The backing pthread_once_t starts all-zero, which is PTHREAD_ONCE_INIT, so no separate init call is needed.
Trait implementations
implement trait Drop for struct Once