Skip to main content

PersistentSection

Struct PersistentSection 

Source
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

Source

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

Source

pub fn parallel_for<F>(&self, chunks: usize, f: F)
where F: Fn(usize) + Send + Sync,

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> and LoopWorkItem both live on the caller’s stack frame. Workers observe them via raw pointers, guarded by two independent invariants:
    1. inflight_derefs: workers increment before any deref of loop_ptr; main spin-waits it back to zero after clearing current_loop, so main cannot return (and the stack frame cannot drop) while any worker is mid-deref.
    2. loop_gen: monotonic counter, bumped by main at publish and again at clear. Workers snapshot it before the inflight_derefs bump and re-check under the guard. Covers the stack-reuse ABA window where main returns, re-enters parallel_for, and allocates a new LoopWorkItem at the same stack address: the pointer match is not enough to distinguish “same loop” from “recycled frame with different exec/ctx/total_chunks values”, but loop_gen changes 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_add on the same counter, amortising the launch latency.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.