A synchronization primitive which can be used to run a one-time global
initialization. Useful for one-time initialization for FFI or related
functionality. This type can only be constructed with the
Creates a new
Performs an initialization routine once and only once. The given closure
will be executed if this is the first time
call_once has been called,
and otherwise the routine will not be invoked.
This method will block the calling thread if another initialization routine is currently running.
When this function returns, it is guaranteed that some initialization has run and completed (it may not be the closure specified). It is also guaranteed that any memory writes performed by the executed closure can be reliably observed by other threads at this point (there is a happens-before relation between the closure and code executing after the return).
If the given closure recursively invokes
call_once on the same
instance the exact behavior is not specified, allowed outcomes are
a panic or a deadlock.
f will only be executed once if this is called
concurrently amongst many threads. If that closure panics, however, then
it will poison this
Once instance, causing all future invocations of
call_once to also panic.
This is similar to poisoning with mutexes.
pub fn call_once_force<F>(&self, f: F) where[src]
Performs the same function as
call_once except ignores poisoning.
call_once, if this
Once has been poisoned (i.e., a previous
call_once_force caused a panic), calling
call_once_force will still invoke the closure
f and will not
result in an immediate panic. If
f panics, the
Once will remain
in a poison state. If
f does not panic, the
Once will no
longer be in a poison state and all future calls to
call_one_force will be no-ops.
f is yielded a
OnceState structure which can be used
to query the poison status of the
pub fn is_completed(&self) -> bool[src]
true if some
call_once call has completed
is_completed will return false in
the following situations:
call_oncewas not called at all,
call_oncewas called, but has not yet completed,
Onceinstance is poisoned
This function returning
false does not mean that
Once has not been
executed. For example, it may have been executed in the time between
is_completed starts executing and when it returns, in which case
false return value would be stale (but still permissible).
Auto Trait Implementations
type Error = Infallible
The type returned in the event of a conversion error.