bimodal_array
bimodal_array provides phase-separated, dual-mode access to a contiguous array.
It enables a scatter–gather access pattern where:
- Independent workers can update elements concurrently.
- A coordinator can later acquire exclusive access to the entire array.
Access Model
Access is granted through two handle types:
ElementHandle<T>— grants mutable access to a single element.ArrayHandle<T>— grants exclusive mutable access to the entire array.
Handles represent the ability to attempt a lock. The actual lock is held by guards:
ElementHandle::lock()returns anElementGuard<T>ArrayHandle::lock()returns anArrayGuard<T>
Locking Rules
- Guards for different elements may be held concurrently.
- An
ArrayGuard<T>provides exclusive access to the entire array. - An
ArrayGuard<T>cannot coexist with anyElementGuard<T>. - Lock acquisition is non-blocking.
Internally, lock state is coordinated via a single AtomicUsize.
As a result, bimodal_array may not scale well under heavy contention.
Example
use bimodal_array;
use thread;
const WORKER_COUNT: usize = 8;
let data = vec!;
let = bimodal_array;
// Scatter phase
let threads: = element_handles
.into_iter
.enumerate
.map
.collect;
for t in threads
// Gather phase
let mut array_guard = array_handle.lock.unwrap;
array_guard.sort;