Module rustc_data_structures::sync
source · Expand description
This module defines various operations and types that are implemented in one way for the serial compiler, and another way the parallel compiler.
Operations
The parallel versions of operations use Rayon to execute code in parallel,
while the serial versions degenerate straightforwardly to serial execution.
The operations include join
, parallel
, par_iter
, and par_for_each
.
Types
The parallel versions of types provide various kinds of synchronization, while the serial compiler versions do not.
The following table shows how the types are implemented internally. Except where noted otherwise, the type in column one is defined as a newtype around the type from column two or three.
Type | Serial version | Parallel version |
---|---|---|
Lrc<T> | rc::Rc<T> | sync::Arc<T> |
Weak<T> | rc::Weak<T> | sync::Weak<T> |
AtomicBool | Cell<bool> | atomic::AtomicBool |
AtomicU32 | Cell<u32> | atomic::AtomicU32 |
AtomicU64 | Cell<u64> | atomic::AtomicU64 |
AtomicUsize | Cell<usize> | atomic::AtomicUsize |
Lock<T> | RefCell<T> | RefCell<T> or |
parking_lot::Mutex<T> | ||
RwLock<T> | RefCell<T> | parking_lot::RwLock<T> |
MTLock<T> 1 | T | Lock<T> |
MTLockRef<'a, T> 2 | &'a mut MTLock<T> | &'a MTLock<T> |
ParallelIterator | Iterator | rayon::iter::ParallelIterator |
1 MTLock
is similar to Lock
, but the serial version avoids the cost
of a RefCell
. This is appropriate when interior mutability is not
required.
2 MTLockRef
is a typedef.
Re-exports
Modules
- freeze 🔒
- lock 🔒This module implements a lock which only uses synchronization if
might_be_dyn_thread_safe
is true. It implementsDynSend
andDynSync
instead of the typicalSend
andSync
traits. - mode 🔒
- parallel 🔒This module defines parallel operations that are implemented in one way for the serial compiler, and another way the parallel compiler.
- vec 🔒
Structs
- This is a single threaded variant of
AtomicU64
,AtomicUsize
, etc. It has explicit ordering arguments and is only intended for use with the native atomic types. You should use this type through theAtomicU64
,AtomicUsize
, etc, type aliases as it’s not intended to be used separately. - A type which allows mutation using a lock until the value is frozen and can be accessed lock-free.
- A guard holding shared access to a
FreezeLock
which is in a locked state or frozen. - A guard holding mutable access to a
FreezeLock
which is in a locked state or frozen. - A type which only allows its inner value to be used in one thread. It will panic if it is used on multiple threads.
- Represents a list of threads which can access worker locals.
- Holds worker local values for each possible thread in a registry. You can only access the worker local value through the
Deref
impl on the registry associated with the thread it was created on. It will panic otherwise. - A wrapper type for a mutably borrowed value from a
RefCell<T>
. - A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
- A wrapper type for a mutably borrowed value from a
RefCell<T>
. - Wraps a borrowed reference to a value in a
RefCell
box. A wrapper type for an immutably borrowed value from aRefCell<T>
. - A wrapper type for a mutably borrowed value from a
RefCell<T>
. - A cell which can be written to only once.
- Wraps a borrowed reference to a value in a
RefCell
box. A wrapper type for an immutably borrowed value from aRefCell<T>
. - A wrapper type for a mutably borrowed value from a
RefCell<T>
.
Enums
- Atomic memory orderings
Traits
Functions
- This gives access to a fresh parallel guard in the closure and will unwind any panics caught in it after the closure returns.