Description
The documentation says that the "Implementation is based on lazy_static and lazy_cell crates and std::sync::Once. In some sense, once_cell just streamlines and unifies those APIs To implement a sync flavor of OnceCell, this crates uses either a custom re-implementation of std::sync::Once or parking_lot::Mutex."
This creates some confusion about how equivalent once_cell::OnceCell
is to std::sync::Once
. In particular, std::sync::Once
guarantees that "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)."
Is this guarantee provided by OnceCell
? I don't think you intend it to be provided, but the statements above in the documentation might lead one to think that OnceCell
is a reimplementation of std::sync::Once
with a different (better) API, when really it implements a similar but more limited (and potentially more efficient) variant.