[−][src]Type Definition arc_swap::strategy::DefaultStrategy
type DefaultStrategy = HybridStrategy<GenLockStrategy<Global>>;
The default strategy.
It is used by the type aliases ArcSwap
and
ArcSwapOption
. Only the other strategies need to be used explicitly.
It is optimized for read heavy situations. The readers are wait-free (with the exception of the
first load
in each thread, which is merely lock-free), writers are not lock-free. The
reclamation is tight ‒ the resource is released as soon as possible.
Each thread has a limited number of "fast" slots. If a thread holds less than this number,
loading is fast and does not suffer from contention (unlike using RwLock
or even updating reference counts on the Arc
). In other words, no matter
how many threads concurrently read, they should not be affecting performance of each other in
any way.
If the slots run out (the thread holds too many Guard
, the loading becomes
slower (because the reference counts need to be updated).
Currently, the implementation is a hybrid between stripped-down hazard pointers and one-sided spin lock. The hazard pointers are the primary fast path. The spin locks are shared between all instances, therefore the fallbacks may influence other instances.
However, the actual implementation can change in future versions for something else with similar or better properties.