pub struct PersistentSection { /* private fields */ }Expand description
Session-scoped parallel region. Construct via
YscvPool::enter_section. Provides
parallel_for for the duration of the section;
the section holds all pool workers in the section worker loop.
Implementations§
Source§impl PersistentSection
impl PersistentSection
Sourcepub fn install_tls(&self) -> SectionGuard<'_>
pub fn install_tls(&self) -> SectionGuard<'_>
Install this section as the thread-local “current section” for
the returned SectionGuard’s lifetime. Consumers call
current_section and route par_chunks_mut_dispatch through
Self::parallel_for when the guard is alive.
Returns a !Send RAII guard; Drop restores the previous TLS
value (nested install_tls stacks correctly).
Sourcepub fn parallel_for<F>(&self, chunks: usize, f: F)
pub fn parallel_for<F>(&self, chunks: usize, f: F)
Post a parallel_for loop. Runs f(0..chunks) concurrently across
the section’s workers plus the main thread (which runs chunks
inline between checks). Blocks until every chunk has completed.
Design notes:
- Zero heap allocation —
Ctx<F>andLoopWorkItemboth live on the caller’s stack frame. Workers observe them via raw pointers, guarded by two independent invariants:inflight_derefs: workers increment before any deref ofloop_ptr; main spin-waits it back to zero after clearingcurrent_loop, so main cannot return (and the stack frame cannot drop) while any worker is mid-deref.loop_gen: monotonic counter, bumped by main at publish and again at clear. Workers snapshot it before theinflight_derefsbump and re-check under the guard. Covers the stack-reuse ABA window where main returns, re-entersparallel_for, and allocates a newLoopWorkItemat the same stack address: the pointer match is not enough to distinguish “same loop” from “recycled frame with differentexec/ctx/total_chunksvalues”, butloop_genchanges across every publish, so the generation mismatch makes the worker skip the deref.
- Condvar/futex-free — workers spin-poll
current_loop; main signals via a pointer store. - Main thread participates: claims chunks via
fetch_addon the same counter, amortising the launch latency.
Auto Trait Implementations§
impl !Freeze for PersistentSection
impl Forget for PersistentSection
impl Move for PersistentSection
impl RefUnwindSafe for PersistentSection
impl Send for PersistentSection
impl Sync for PersistentSection
impl Unpin for PersistentSection
impl UnsafeUnpin for PersistentSection
impl UnwindSafe for PersistentSection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more