Module 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.

TypeSerial versionParallel version
Lock<T>RefCell<T>RefCell<T> or
parking_lot::Mutex<T>
RwLock<T>RefCell<T>parking_lot::RwLock<T>
MTLock<T> 1TLock<T>
ParallelIteratorIteratorrayon::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. 

Re-exports§

pub use self::lock::Lock;
pub use self::lock::LockGuard;
pub use self::lock::Mode;
pub use crate::marker::*;

Modules§

atomic 🔒
Keep the conditional imports together in a submodule, so that import-sorting doesn’t split them up.
freeze 🔒
lock 🔒
This module implements a lock which only uses synchronization if might_be_dyn_thread_safe is true. It implements DynSend and DynSync instead of the typical Send and Sync 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 🔒
worker_local 🔒

Structs§

AppendOnlyIndexVec
AppendOnlyVec
AtomicU64
An integer type which can be safely shared between threads.
CacheAligned
FreezeLock
A type which allows mutation using a lock until the value is frozen and can be accessed lock-free.
FreezeReadGuard
A guard holding shared access to a FreezeLock which is in a locked state or frozen.
FreezeWriteGuard
A guard holding mutable access to a FreezeLock which is in a locked state or frozen.
MTLock
Registry
Represents a list of threads which can access worker locals.
RwLock
WorkerLocal
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.

Constants§

ERROR_CHECKING 🔒
This makes locks panic if they are already held. It is only useful when you are running in a single thread

Traits§

HashMapExt

Functions§

is_dyn_thread_safe
join
par_for_each_in
par_map
parallel_guard
This gives access to a fresh parallel guard in the closure and will unwind any panics caught in it after the closure returns.
scope
set_dyn_thread_safe_mode
try_par_for_each_in

Type Aliases§

MappedReadGuard
An RAII read lock guard returned by RwLockReadGuard::map, which can point to a subfield of the protected data.
MappedWriteGuard
An RAII write lock guard returned by RwLockWriteGuard::map, which can point to a subfield of the protected data.
ReadGuard
RAII structure used to release the shared read access of a lock when dropped.
WriteGuard
RAII structure used to release the exclusive write access of a lock when dropped.